I'm not sure how to word the question, and I'm not finding anything in searches.
I have a variable, and want to pass it into f.open() as the name of the file to open.
The goal is to type a file name into foo, then it clears the files.
foo = str(raw_input('enter a filename '))
bar = foo
f = open('foo', 'w')
f.write("")
f.close()
I've tried using open(foo, 'w') and replacing it with 'bar', but neither seems to work. Any suggestions?
stris unnecessary when you getraw_inputf.write("")can be removed. You can even writeopen(foo, 'w').close().