Re: open() and file CREATION

Guido.van.Rossum@cwi.nl
Fri, 11 Feb 1994 23:23:30 +0100

> How do I CREATE a file from Python? I normally just OPEN an already
> existing file.. Now I need to CREATE one.. open() will not do it..
> I looked in the INFO file for builtin functions and could not find one..

Python's open() passes its two arguments straight to stdio's fopen().
If you C library supports (as it should) fopen(filename, "w") to
create a file, Python's open(filename, 'w') should do so too. If it
doesn't, you have a bug (but the test set tests this case so I
suspect you simply haven't tried hard enough or there is a permission
problem in the directory).

> Also, why are there no flags defined in the posix module?
> Flags like:
>
> O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_SYNC, O_APPEND, O_CREAT,
> O_TRUNC, O_EXCL, O_NOCTTY

Probably because I haven't really ever used posix.open() for anything
more complicated than O_RDONLY which can be assumed to 0...

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>