Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ENV variable in Python
#1
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.
Reply
#2
Use
pwdfile='{}/admin/data/pswds'.format(NAS1)
Do you HAVE to use python 2?
Reply
#3
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020