我的函數的基本思想是:我試圖複製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