Python Forum

Full Version: ENV variable in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have this simple code:

#!/usr/bin/env python

import sys, re, os

NAS1=os.environ['NAS1']
print 'Value of NAS1: ' + NAS1

pwdfile='NAS1/admin/data/pswds'
print 'Value of pwdfile: ' + pwdfile
When I run this code, the "pwdfile" variable doesn't pick up the "NAS1" value from 2 lines above it.

Output:
$ ./search.py Value of NAS1: /u01/app/oracle/NAS1 Value of pwdfile: NAS1/admin/data/pswds
Expected output for 'pwdfile' = /u01/app/oracle/NAS1/admin/data/pswds

Please help me understand what I am doing wrong here. Thanks in advance.
Use
pwdfile='{}/admin/data/pswds'.format(NAS1)
Do you HAVE to use python 2?
Thanks, Griboullis. I didn't even realize that I have been studying Python 2.7 when I started Python coding last week. Looks like I have to reset everything and start afresh with 3.7. Thanks so much for the pointer.