在保存 Python 生成的文件时,我试图让自己免于执行旧的复制和过去的技巧。默认保存到 Python 目录,但我希望它是:C:\Program Files\Vixen\Vixen 2.1.1.0\Routines
我试过这个:
import os
filename = raw_input('What would you like to name the file? ')
filepath = os.path.join("C:\Program Files\Vixen\Vixen 2.1.1.0\Routines",filename)
with open(filename, 'wb') as out:
for frame in frames:
out.write(' '.join(str(num) for num in frame))
out.write(' ')
out.write('\n')
我得到的错误是:
Traceback (most recent call last):
File "(stdin)", line 1 in (module)
File "comet.py", line 169, in (module)
filepath= os.path.join("C:\Program Files\Vixen\Vixen 2.1.1.0\Routines",filename)
NameError: name 'os' is not defined
如何让 Python 将文件直接保存到所需的路径中?