python os.rename “”cannot create a file when that file already exists
问题 K.. I'm just using a simple script I found here: import os from os import rename, listdir print os.listdir(".") for filename in os.listdir("."): if filename.startswith("colon-"): print filename os.rename(filename, filename[7:]) I need to basically take all files like colon-21.mp3 converted to 21.mp3. But I get the error CANNOT CREATE A FILE WHEN THAT FILE ALREADY EXISTS. How does one solve this? I am using Windows 7. 回答1: The problem is right here: os.rename(filename, filename[7:]) Python