beginners syntax question

logistix logstx at bellatlantic.net
Sat Apr 6 15:04:01 EST 2002


If you really need to do this with strings, and can't make a list like the
others suggested, use a dictionary to translate strings to objects.  Python
also provides two builtin functions global() and local() that return the
respective global and local namespace dictionaries.

>>> x,y = 1,2
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>,
 '__doc__': None,
 '__name__': '__main__',
 'pprint': <function pprint at 0x01508790>,
 'pywin': <module 'pywin' from
'C:\PYTHON22\lib\site-packages\Pythonwin\pywin\__init__.pyc'>,
 'x': 1,
 'y': 2}
--
-

"Tony" <tonyl at homechoice.co.uk> wrote in message
news:3caf47a5 at news1.homechoice.co.uk...
> Hi,
>
> I'm trying to call the update() method of several objects ie:
>
> object1.update()
> object2.update()
> etc
>
> I'd really like to do
>
> for x in range(7):
>   "object"+str(x).update
>
> but can't figure outthe syntax, is this possible?
>
> Thanks
> Tony
>
>
>





More information about the Python-list mailing list