Creating a new file

Paul Osman posman at eval.ca
Sun Sep 21 20:39:01 CEST 2003


On Sun, 21 Sep 2003, anthony polis wrote:

> Hello,
> 
> I'm new to Python. Is it possible to create a NEW file in Python? I read the 
> tutorial on file input in the documentation but it only explains how to work 
> with existing files. Can someone point me in the right direction?
> 
> Thanks,
> Anthony
> 

Sure, just open a file in write mode, i.e.:

fp = open("output.txt", "w")
fp.write("Hello")
fp.close()

HTH,
-- 
Paul Osman
posman at eval.ca
http://perl.eval.ca

"Idealists...foolish enough to throw caution 
  to the winds...have advanced mankind and have 
  enriched the world."
         - Emma Goldman





More information about the Python-list mailing list