python在读写文件的时候会报错:ValueError: embedded null character,此问题主要是文件的路径问题导致的,仔细观察发现路径中有个‘\0’,文件路径中若包含‘\0’、'\t' 等特殊转义字符时要特别注意。
Traceback (most recent call last):
File "E:/009_Python/py_test4.py", line 1, in <module>
f=open('E:\009_Python\test\t01.txt','w',encoding='utf-8')
ValueError: embedded null character
正确写法:
1、双引号+双斜杠
f = open("E:\\009_Python\\000_Temp\\t01.txt", 'w')
2、单引号+反斜杠
f = open('E:/009_Python/000_Temp/t01.txt', 'w')
1331

被折叠的 条评论
为什么被折叠?



