"Paul Hankin" <[EMAIL PROTECTED]> wrote in message news:fdff5a3c-376c-41da-bc7c-| > Do you want to do this?: | > locals()['var'+str(1)] = "spam" | | As I recently learnt in this newsgroup, that's not guaranteed to work. | >From http://docs.python.org/lib/built-in-funcs.html | | Warning: The contents of this dictionary should not be modified; | changes may not affect the values of local variables used by the | interpreter.
It currently works at module level, where locals() is globals(). But then, one might as well write globals()['var'+str(1)] = "spam". But in Python, one is almost certainly better to use a collection object than this idiom (indefinite multiple numbered variables) imported from languages which do not have them. -- http://mail.python.org/mailman/listinfo/python-list