How to do this? - newbie

Marc Christiansen tolot at utolot.toppoint.de
Thu Feb 10 19:27:44 EST 2000


Ronald L. <dilsavor at erinet.com> 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)

If I got you right, then exec is what you want: 'exec a[0]+"="+str(a[1])' 
(or 'exec "%s=%d"%(a[0],a[1])' ) will execute 'x=1'.

Ciao
  Marc



More information about the Python-list mailing list