How to do this? - newbie

Steve Holden sholden at bellatlantic.net
Thu Feb 10 11:59:10 EST 2000


"Ronald L. Dilsavor" wrote:
> 
> Hi,
> I am new to python and am quite excited about it. I spent much of last night
> writing my fist code snippet and I came across 1 thing which I could not
> figure out how to do.
> 
> Suppose
> 
> >>> a=('x',1)
> then how can I create an x of numerical type such that
> >>> print x
> 1
> 
>  - just using manipulations of a = ('x',1)
> 
> Also let me know if this type of thing would not be considered best practice
> in python. I thought I would need to make use of eval() but could not find
> an incantation that would do it.
> 
> Thanks,
> Ron
I am sure there are people reading this group who can tell you
how to dynamically construct something which will create a
variable called a and assign it the value 1.

But it seems you really want to be able to retrieve the numeric
value using the symbol 'a' as a key, and that's what dictionaries
are for.

>>> mydict={}		# empty dictionary
>>> mydict['a']=1	# enter value 1 against key 'a'
>>> print mydict['a']	# retrieve the value
1
>>>

Is *that* what you want?

regards
 Steve


--
"If computing ever stops being fun, I'll stop doing it"



More information about the Python-list mailing list