我剛剛成立了一個新的Python腳本,當我運行它,我得到的錯誤代碼:有錯誤代碼,如果語句
File "conversion.py", line 17
elif filetype == "Audio":
^
我的代碼是:
if filetype == "Document":
path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
os.chdir(path[1:-2])
filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .txt: ")
from subprocess import check_call
subprocess.check_call(['unoconv', '-f', Fileextension, filename])
elif filetype == "Audio":
path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
os.chdir(path[1:-2])
filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .mp3: ")
body, ext = os.path.splitext("filename")
check_call(["ffmpeg" ,"-i", filename, body Fileextension])
elif filetype == "Video":
path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
os.chdir(path[1:-2])
filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .mp4: ")
body, ext = os.path.splitext("filename")
from subprocess import check_call
check_call(["ffmpeg" ,"-i", filename, body Fileextension])
elif filetype == "Image":
path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
os.chdir(path[1:-2])
filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. .Jpeg: ")
body, ext = os.path.splitext("filename")
from subprocess import check_call
check_call(["ffmpeg" ,"-i", filename, body Fileextension])
沒有任何人有任何想法至於這裏的錯誤是什麼。任何解決方案將非常感激。我一直試圖解決它一個小時,我仍然不知道爲什麼會發生。
'subprocess.check_call(['unoconv','-f',Fileextension,filename])'識別,是錯誤類型? –
什麼是完整的錯誤信息,並且您的縮進是否正確?你的'subprocess'行不縮進。如果應該,請修復它。如果不是,那是你的錯誤。 – Andy
這並不能解決你目前的問題,但是當[你以前的問題](http://stackoverflow.com/questions/30459232/error-with-subprocess-in-python-script)的回答者告訴你刪除你的'+'操作符,我認爲他的意思是隻在逗號後面出現的那些操作符。你應該把check_call([「ffmpeg」,「 - i」,filename,+ body + Fileextension])'變成'check_call([「ffmpeg」,「 - i」,filename,body + Fileextension]), 'check_call([「ffmpeg」,「 - i」,filename,body Fileextension])'。 (或者也許它應該是'check_call([「ffmpeg」,「 - i」,filename,body,Fileextension])?) – Kevin