例如,表示Windows目录的最佳方法是什么"C:\meshes\as"?我一直在尝试修改脚本,但它永远不会起作用,因为我似乎无法正确获取目录,我假设因为'\'扮演转义角色?
我不知道为什么,但出于某种原因,每当我在输出文件的文件名中有"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
Run Code Online (Sandbox Code Playgroud)
为什么是这样?我真的想将我的文件命名为"regionlog.txt",但它不断出现这个错误.有办法解决吗?
我无法在 python(完整路径)中创建文件。
代码:
with open('C:/Users/Kobe/backtra/data/BTC-USDT_25-05-20-19:02:19.json', "w+"):
pass
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File ".\createFile.py", line 1, in <module>
with open("C:/Users/Kobe/backtra/data/BTC-USDT_25-05-20-19:02:19.json", "w+"):
OSError: [Errno 22] Invalid argument: 'C:/Users/Kobe/backtra/data/BTC-USDT_25-05-20-19:02:19.json'
Run Code Online (Sandbox Code Playgroud)