By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,543 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,543 IT Pros & Developers. It's quick & easy.

Retrieve ext. variables in python program

P: n/a
Trying to convert TCL code to python.

Have a property file from where I read some VAR's. Looks like this:
EARPROJECT = sgs-procDist
APPNAME = SGSProcedure
In my TCL code I confirm the existence of the VAR = f.ex EARPROJECT by
using code:

if { ([info exists APPNAME] && [info exists STAGEDIR] && [info exists
EARPROJECT] && [info exists EARDESTINATION]) } {
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???

Jul 19 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
alfa1234:
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???
Using globals(), locals(), and dir() you can find if your name exists
already.

Bye,
bearophile

Jul 19 '06 #2

P: n/a

be************@lycos.com skrev:
alfa1234:
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???

Using globals(), locals(), and dir() you can find if your name exists
already.

Bye,
bearophile
Hi bearophile !!
Thanks for the answer..Tried to use these methods, but with no luck.

What needed is a way for my code to look at the external property file
with the lines:
>>earProject = sgs-procDist
Appname = SGSProcedure
and accept "earProject" and "Appname" as a Variable if they exist...

Can Y help here..??
Rgds alfa1234

Jul 19 '06 #3

P: n/a
alfa1234 wrote:
Trying to convert TCL code to python.

Have a property file from where I read some VAR's. Looks like this:
EARPROJECT = sgs-procDist
APPNAME = SGSProcedure
In my TCL code I confirm the existence of the VAR = f.ex EARPROJECT by
using code:

if { ([info exists APPNAME] && [info exists STAGEDIR] && [info exists
EARPROJECT] && [info exists EARDESTINATION]) } {
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???
You can read it with the module ConfigParser

Diez
Jul 19 '06 #4

P: n/a
Hi Diez !!
Thanks for the reply.. Tried a little well dokumented program:

# file: construct.ini
retries = 10

# file: construct.py
import cfgparse
c = cfgparse.ConfigParser()
c.add_option('retries', type='int')
c.add_file('construct.ini')
opts = c.parse()
print 'Number of retries:',opts.retries

Got the following Error when trying to run code:
[wsadmin] Traceback (innermost last):
[wsadmin] File "<string>", line 1, in ?
[wsadmin] ImportError: no module named cfgparse

Jul 19 '06 #5

P: n/a

Diez B. Roggisch skrev:
alfa1234 wrote:
Trying to convert TCL code to python.

Have a property file from where I read some VAR's. Looks like this:
EARPROJECT = sgs-procDist
APPNAME = SGSProcedure
In my TCL code I confirm the existence of the VAR = f.ex EARPROJECT by
using code:

if { ([info exists APPNAME] && [info exists STAGEDIR] && [info exists
EARPROJECT] && [info exists EARDESTINATION]) } {
Does anyone know and equalent way to confirm a Variable from the same
property file using PYTHON code ???

You can read it with the module ConfigParser

Diez
[wsadmin] Traceback (innermost last):
[wsadmin] File "<string>", line 1, in ?
[wsadmin] ImportError: no module named cfgparse

Jul 19 '06 #6

P: n/a
In <11*********************@m79g2000cwm.googlegroups. com>, alfa1234 wrote:
Hi Diez !!
Thanks for the reply.. Tried a little well dokumented program:

# file: construct.ini
retries = 10

# file: construct.py
import cfgparse

c = cfgparse.ConfigParser()
c.add_option('retries', type='int')
c.add_file('construct.ini')
opts = c.parse()
print 'Number of retries:',opts.retries

Got the following Error when trying to run code:
[wsadmin] Traceback (innermost last):
[wsadmin] File "<string>", line 1, in ?
[wsadmin] ImportError: no module named cfgparse
Well, the message is quite descriptive. There is no module named
`cfgparse`. Diez suggestet the `ConfigParser` modul. You notice the
difference?

Ciao,
Marc 'BlackJack' Rintsch
Jul 19 '06 #7

P: n/a

Marc 'BlackJack' Rintsch skrev:
In <11*********************@m79g2000cwm.googlegroups. com>, alfa1234 wrote:
Hi Diez !!
Thanks for the reply.. Tried a little well dokumented program:

# file: construct.ini
retries = 10

# file: construct.py
import cfgparse

c = cfgparse.ConfigParser()
c.add_option('retries', type='int')
c.add_file('construct.ini')
opts = c.parse()
print 'Number of retries:',opts.retries

Got the following Error when trying to run code:
[wsadmin] Traceback (innermost last):
[wsadmin] File "<string>", line 1, in ?
[wsadmin] ImportError: no module named cfgparse

Well, the message is quite descriptive. There is no module named
`cfgparse`. Diez suggestet the `ConfigParser` modul. You notice the
difference?

Ciao,
Marc 'BlackJack' Rintsch
Hi Marc !!
Did manage to download cfgparse-0.1.tar.gz which include the
"cfgparse.py" module and the program seem to find the module , but when
running above sample I now get the

[wsadmin] ImportError: no module named Configparser

Im not sure about this, but Im running all this using the Websphere 6.0
jython interface(classes = jython.jar)..
Do I need some additional Python implementation in order for the pyton
programs to run properly ??
I really appreciate your help out there guys...

Jul 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.