我不知道为什么,但出于某种原因,每当输出文件的文件名中有“region”时,就会出现以下错误:
IOError:[Errno 22]无效模式(“w”)或文件名:“path\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”,但它总是出现这个错误。有办法绕过吗?
此外,当尝试从SharePoint共享驱动器打开文件>;50 MB时,Python还会给出此消息。
https://support.microsoft.com/en-us/help/2668751/you-cannot-download-more-than-50-mb-or-upload-large-files-when-the-upl
在C标准语言中,
\t
,\n
,\r
是转义字符。\t
是下一个制表位的横线。\n
是换行符,\r
是回车符。你应该使用\\r
或/r
,你就能解决问题!使用正斜杠:
或原始字符串:
或者至少摆脱你的反睫毛:
\r
是回车。另一个选择是:使用
os.path.join
,您根本不必担心斜杠:相关问题 更多 >
编程相关推荐