Mahmood Naderan wrote:

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;*

import os

infile = open(os.path.join(env, 'sc_1.sh'),"r")

JM
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to