473,378 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Retrieve ext. variables in python program

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
7 1922
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

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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Lindstrom | last post by:
Hello- I am running python 2.3. on an HP-9000 box running Unix and have a POSIX script that sets up my production environment. I would like to run the script from inside a python routine and...
181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
2
by: MrEntropy | last post by:
Greetings, I'm having a little trouble getting an idea running. I am writing a C program which is really a frontend to a Python program. Now, my C program starts up, does some initialisation like...
1
by: Crutcher | last post by:
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program,...
6
by: Burton Samograd | last post by:
Hi, I'm writing an app that stores some user configuration variables in a file ~/.program/config, which it then imports like so: import sys from posix import environ...
3
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
7
by: MD | last post by:
Hi, I would like to access "variables" defined in my Python program in a C module extension for Python. Is this possible? I looked at the Python C API reference but didn't find anything there...
12
by: Kevin Walzer | last post by:
I'm trying to learn C. I have a fairly extensive background with C-based scripting languages (Python,Tcl, others), so a great deal of C is proving easy to pick up (control structures, functions,...
0
by: Gary Herron | last post by:
Jacob Davis wrote: Yuck, YUCK, YUCK! You are breaking *so* many good-programming-practices, I hardly know where to start. First off: A python global is not what you think. There are *no*...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.