function parameter: question about scope
Emile van Sebille
emile at fenx.com
Sun Jul 14 12:14:08 EDT 2002
More information about the Python-list mailing list
Sun Jul 14 12:14:08 EDT 2002
- Previous message (by thread): Is there a Python text-editor suitable to embed in a VB app (newbie question)
- Next message (by thread): function parameter: question about scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Uwe Mayer
> def getElements(self, types, memo={}):
[snip]
> The problem is, that 'memo' seems to live beyond method invocation -
and
> I don't know why:
When you use:
def getElements(self, types, memo={}):
memo will only be created once when the module is initially imported.
All subsequent access to getElements() that don't specifically override
memo share the same originally created copy of memo. You probably want
to do:
def getElements(self, types, memo=None):
if memo == None:
memo = {}
Then each invocation of getElements not passing in memo will get a newly
created memo.
HTH,
--
Emile van Sebille
emile at fenx.com
---------
- Previous message (by thread): Is there a Python text-editor suitable to embed in a VB app (newbie question)
- Next message (by thread): function parameter: question about scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list