File creation

Luca Fini lfini at arcetri.astro.it
Sat Nov 24 19:38:27 EST 2001


On Sun, 25 Nov 2001, Aaron Sterling wrote:

> Hi,
> 
>     To create files, I am currently using:
>         
>         temp_file = os.open(file_name, O_CREAT)
>         temp_file.close()
>         open(file_name, 'w')
> 
>     Is this the cannonical way of doing it?  If so, would it be usefull to have a function, create_file(file_name, mode, bufsize), linked to the interpreter, that 
> would create the file and return an associated file object? Is their a better way to do it, or is it something that shouldn't be done, and if so why?

It is quite simpler than that:

>>> fd=open('filename','w')
>>> fd
<open file 'filename', mode 'w' at 0x80e8fe8>

the open() function in write mode creates the file if it's not existing. 
Otherwise it truncates the existing file (i.e.: overrides the previous 
content)

Cheers,

					l.f.
 -- 
--------------------------------------------------------------------------
       -- )     Luca Fini                            Tel: +39 055 2752 307
 ___    |\      Osservatorio Astrofisico di Arcetri  Fax: +39 055 2752 292
/   |   | |-_   L.go E.Fermi, 5 +-----------------------------------------
(___|___//___)  50125 Firenze  /   WWW: http://www.arcetri.astro.it/~lfini
 (_)      (_)   Italia        / e-mail: lfini at arcetri.astro.it
-----------------------------+--------------------------------------------




More information about the Python-list mailing list