[Tutor] write to a file in linux (again)!

alan.gauld@bt.com alan.gauld@bt.com
Wed, 21 Aug 2002 18:30:42 +0100


> ok i did this and it works in the shell but whenever i implement it in
> the script im running i get this error
> 
> Traceback (most recent call last): File
> "/var/www/backbone/admin/newdesign/papers/cgi/final.py", line 58, in ?
> newpy = open(newpyfile, "w") IOError: [Errno 2] No such file or
> directory: 'newdesign/papers/cgi/1.py' 

This is a guess but...

Is 

newdesign/papers/cgi 

supposed to be a relative path? Or should it really be:

/newdesign/papers/cgi

Just a thought. 

> well of coarse its not a file or directory im creating a new 
> one 

If the directory doesn't exist python won't 
create it, it will only create the file itself.
If you want to create the path as well you'll 
need to use something else, probably in the 
os module...

os.mkdirs() looks like the one you would need.

HTH,

Alan g.