creating a file from python

Greg Ewing see_reply_address at something.invalid
Thu Jul 4 20:37:01 EDT 2002


> gollem wrote:
> 
>> I want to create a file from inside a running python script.
>> I can do that using commands and touch but it won't work if the intended
>> name of the file is the value of a python variable.


You mean you just want to create an empty file?
This will do it:

   filename = "some_file_name"
   f = open(filename, "w")
   f.close()

Names of your Python variables don't come into it at all.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list