我的函数的基本思想是:我试图复制unix命令“cd ../”(这会导致父目录被选中),但是我希望能够输入“cd”。 ./../“(作为命令行参数)。递归函数调用
所以我正在尝试递归调用。该函数将查找一个字符串是否包含“../”,如果是,请调用我的函数upOneDir()(它将有效地将程序的目录更改为父目录),然后调用自身(dotDotSlash())。
def dotDotSlash():
s = sys.argv[2]
dotDotSlash = "../"
if (s.find(dotDotSlash) == -1):
print "not found"
else:
print "found ../ at: "
print s.find(dotDotSlash)
upOneDir()
dotDotSlash()
功能,当我试图进入执行一次“CD ../../”,然后给了我这个错误:
Traceback (most recent call last):
File "test3.py", line 59, in <module>
dotDotSlash()
File "test3.py", line 40, in dotDotSlash
dotDotSlash()
TypeError: 'str' object is not callable
为什么功能不调用任何想法本身正确?
使用getopt它的python内置它将满足您的需求。 –
你将你的变量命名为你的函数 –
'dotDotSlash =“../”'是同名的字符串'def dotDotSlash()'改变变量名或函数名。 – Nilesh