我有一大組帶有.PNG擴展名的圖像(比如image00.PNG)。我想將它轉換成.png(小寫)。我從互聯網上得到了一個腳本,但無法處理。將圖像名稱擴展名從.PNG轉換爲Python中的.png
這裏的腳本:
files = os.listdir(cur_dir)
for filename in files:
file_ext = os.path.splitext(filename)[1]
if old_ext == file_ext:
newfile = filename.replace(old_ext, new_ext)
os.rename(filename, newfile)
當我嘗試在終端上運行它,我得到的錯誤:
NameError: name 'filename' is not defined
可能是什麼問題呢?
哪條線扔的錯誤? – Dogbert
問題是,你沒有向我們展示真實的代碼。 –
當你運行你發佈的代碼時,我有一個「old_ext」未定義,這是真的......向我們展示真實的代碼;) –