2009-12-27 80 views
0

我剛開始學習Python ......如此忍受我請爲什麼「def InvalidArgsSpecified:」語法錯誤?

爲什麼給我一個無效的語法錯誤用的代碼塊

def InvalidArgsSpecified: 
    print ("*** Simtho Usage ***\n") 
    print ("-i Installs Local App,, include full path") 
    print ("-u Uninstalls Installed App,include ID or Name") 
    print ("-li Lists all installed Apps and their ID") 
    print ("-all Lists All Apps in Repository") 
    print ("-di Downloads and Installs App from repository, enter the title or id number") 
    print ("-dw Downloads and Installs Single App from a full link") 
    print ("-rmall Removes All Packages installed and removes Simtho itself\n") 
    print ("*** End of Simtho Usage ***") 
    sys.exit() 

編輯:現在,它說這是在行未定義9 9號線是

InvalidArgsSpecified() 

回答

6

的語法錯誤是在第一行,那就是你有:

def InvalidArgsSpecified: 

將其更改爲:

def InvalidArgsSpecified(): 

這些括號是強制性的def,即使有它們之間(就像括號總是用來通話的功能沒有什麼 - 空括號,在這種情況下, ,如果你沒有參數調用)。

編輯:現在OP的得到一個錯誤試圖調用這個函數在第9行:因爲這個函數的定義是超過900行,它可能獲取調用(從模塊的頂層,而不是從內另一函數),在這種情況下,簡單的修復方法是在之後定義它,只調用。如果它是什麼比這更微妙,我們需要看到的代碼進行調試你 - )

+0

看到上面的編輯請 – 2009-12-27 23:12:52

+2

@Indebi,看到並回應,雖然問題與其中的問題不是一個問題,但與穀物和SO的正常行爲背道而馳!如果你有一個錯誤,就此提出一個問題,相應地修正這個錯誤,從而揭示一個新的完全不同的錯誤,正常的有禮貌的行爲就是接受修正你的錯誤的答案,並且打開一個關於新的和單獨的問題的單獨問題。完全不同的錯誤。 – 2009-12-27 23:19:07

+0

randomgarbagetoletmecomment 謝謝,它的工作 – 2009-12-27 23:25:34

2

的函數不帶參數還必須包括括號,如:!

def InvalidArgsSpecified(): 
+0

看到上面的編輯請 – 2009-12-27 23:14:18