I’m trying to save myself from performing the old copy and past trick when saving files that Python generates. The default is saving to the Python directory, however I would like it to be: C:\Program Files\Vixen\Vixen 2.1.1.0\Routines
I have tried this:
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')
And the error I get is this:
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
How can I get Python to save the file directly into the desired path?
You forgot to load the os library. You can do that with
import osprior to your code.Edit: Another problem is that you are defining the path variable but are not using it anywhere apart from the assignment.
Try to change the following:
with open(filename, 'wb') as out:towith open(filepath, 'wb') as out: