0
這個非常奇怪的問題,我的代碼工作正常,在我的機器上(Linux Mint的),但它顯示的錯誤在我的服務器os.listdir的路徑包含空白
這裏的代碼 - 注意,我讓abspath
甚至是沒有它在我的機器中工作正常!
def GET_Contents(filepath):
return os.listdir(os.path.abspath(os.path.join('files', filepath.strip())))
這裏的給定異常 return os.listdir(os.path.abspath(os.path.join('files', filepath.strip()))) OSError: [Errno 2] No such file or directory: '/home/hamoud/webapps/FileManager/files/EE201/MID 1'
與包含空格的文件夾只出現問題(如MID 1
)
但是,產生MID1而不是MID 1,那麼它不存在的另一個文件 – Hamoudaq
@EngHamoud:那麼你不清楚你在問什麼。 *然後存在哪個文件夾? –
@EngHamoud:注意'os.path.abspath()'產生的完整路徑;你給它一個相對路徑('files/EE201/MID 1'),所以Python使它成爲相對於當前工作目錄的完整路徑。如果你的文件在其他地方居住*你需要給它正確的絕對路徑。 –