Using dictionaries

Gilles Lenfant glenfant at equod.com.nospam
Tue Dec 5 05:01:31 EST 2000


Hi,

Can't understand why you're doing complicated when something simple can
work.
You don't need to use a dictionnary to do this.
If a simple way like this does not work for you, there's something I did not
get from your post.
--- configuration.py (start)---
...
Val1 = 1
Val2 = 'myserver'
Valn = 500
...
--- configuration.py (end)---
--- main.py (start) ---
...
from configuration import *
...
xyz = Val1 + Valn
...
--- main.py (end) ---

"sorular" <sorular at netscape.net> a écrit dans le message news:
3a2c9264.503856587 at news-server.bigpond.net.au...
> G'day
>
> I am trying to write a python program where a "configuration.py" will
> have all the user entered values in a dictionary format and a
> "main.py" which will import these and use it as local parameters.
>
> But, there are quite a few values in the dictionary
> ie
> dict = { 'key1':'value1' , ' key2':'value2' , ......'keyN':'value2'}
>
> and in the "main.py" these will be all renamed with the local names
> ie
> Val1 = dictionary.dict['key1']
> Val2 = dictionary.dict['key2']
> ....
> ValN = dictionary.dict['keyN']
> etc....
>
> But overall, I still have a large numbe of values (ValN) to list... !
>
> Q1- Is there a more efficient way to do this ? I thought about using a
> for loop but that didnt work....
>
> Q2 - would it be possible only to list the parameters in first file
> (ie dictionary.py
> key1 = value1
> key2 = value2
> .....
> keyN = valueN
> )
> and inside main.py, do a simple import...
> import dictionary *
> so that key1 can be used inside main.py as a local parameter?
>
> thank
>
> HK




More information about the Python-list mailing list