Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Sourcing a variable from an external file

Status
Not open for further replies.

Winstonb

Technical User
Aug 11, 2001
29
GB
Hello,

I'm new to Python (Jython) and would like to know how I can run a Python (Jython) script which uses a variable which is sourced from an external properties file.

A very simple eg could be as per below.....

Contents of external properties file:
var1 = server1

Contents of Python(Jython) script:
print var1

Output:
server1

Thanks in advance
Winston
 
If you name one file config.py with
var1 = "servername"

Then you can import it into your script

import config
print config.var1

Else you could use a 3rd party module called configobj and have ini style configs



"If you always do what you've always done, you will always be where you've always been."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top