passing environment variable path to open command

Mahmood Naderan nt_mahmood at yahoo.com
Fri Jun 11 04:39:40 EDT 2010


Hi,
I am new to python so my question may be very basic.
Suppose I have a file (sc_1.sh) which the path to that file is in system path:
SOMETHING=/home/mahmood/scripts
 
Now I want to open that file with respect to the environment variable:
   import os
   env = os.getenv("SOMETHING")
   print env
   infile = open("env/sc_1.sh","r")
 
But here is the error I get:
/home/mahmood/scripts
Traceback (most recent call last):
  File "test.py", line 7, in <module>
    infile = open("env/sc_1.sh","r")
IOError: [Errno 2] No such file or directory: 'env/sc_1.sh'
 
How can I use such variable in open file command?
Thanks,
 
// Naderan *Mahmood;


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100611/e7778a68/attachment.html>


More information about the Python-list mailing list