[Tutor] crontab or python mistake

Andreas Kostyrka andreas at kostyrka.org
Fri May 26 13:19:35 CEST 2006


Am Freitag, den 26.05.2006, 08:32 +0100 schrieb Alan Gauld:
> <snip>
> > IOError: [Errno 2] No such file or directory: ' emmssg.txt'
> </snip>
> >
> > the emmssg.txt file is in the /root/script directory so i 
> > don't know why it cant find it.
> 
> The file may be there but crontab isn't. It runs the program 
> as root and root's home directory is /.
> 
> For this kind of thing you need to either pass in the 
> data directory as an argument or wrap the python script 
> in a shell script that sets an environment variable to 
> where your data is and then runs the pyhon script. 
> Within the script use getenv to find the path.

Well, he can do the following stuff:
-) wrap it in a shell script that changes to current directory to the
expected one.
-) do that inside the python script.
-) make the file path absolute somehow:
   *) code it as a constant int the script.
   *) make it an argument (see sys.argv or module optparse)
   *) make it an argument via the environment (os.environ, not getenv)

Andreas


> 
> Or just hard code the path...
> 
> Alan G
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20060526/32b42f52/attachment.pgp 


More information about the Tutor mailing list