我不知道爲什麼,但由於某種原因,只要我在輸出文件的文件名中有「region」,它就會給我此錯誤:Region:IOError:[Errno 22] invalid mode('w')or filename
IO錯誤:[錯誤22]無效的模式( 'W')或文件名: '路徑\ regionlog.txt'
它這樣做是爲「region.txt」,「 logregion.txt「等
class writeTo:
def __init__(self, stdout, name):
self.stdout = stdout
self.log = file(name, 'w') #here is where it says the error occurs
output = os.path.abspath('path\regionlog.txt')
writer = writeTo(sys.stdout, output) #and here too
這是爲什麼?我真的想將我的文件命名爲「regionlog.txt」,但它不斷出現該錯誤。有沒有辦法解決它?
第三個選項:雙斜線。 – 2013-02-28 17:25:22
第四種選擇:使用'os.path.join'。 OP已經導入了'os.path'。 – 2013-02-28 17:26:08