理由はわかりませんが、出力ファイルのファイル名に "region"があるときはいつでもこのエラー:地域:IOError:[Errno 22]無効なモード( 'w')またはファイル名
例外IOError:[errnoを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"の名前を付けたいですが、それはそのエラーを思い付いていきます。その周りに道がありますか?
第三のオプションでは "\ R" インスタンスを変更しています。 –
第4オプション: 'os.path.join'を使います。 OPはすでに 'os.path'をインポートしました。 –