Problem getting to my variables

Steve Holden sholden at
Wed Aug 22 00:42:39 CEST 2001

"vio" <vmilitaru at> wrote in message
news:3B772142.81AA45FD at
> Newbie question: What's the syntax for accessing a variable in one method
> another. Say the two methods:
> ----------
> def manage_addFoo(self, id, title, REQUEST=None):
>     . . .
>     A_folder = getattr(base_folder,someID)
>     . . .
> def manage_addBar(self, id, REQUEST=None):
>     . . .
>     manage_addFoo.A_folder._setObject(id, BarObject)
>     . . .
> ----------
> Just to give some context, this is Zope code: in the second method I
simply want
> to add an object to 'A_folder' which is defined in the first method. I
> like to know what's the correct syntax (obviously my line 4 is wrong). And
> don't want to use 'return A_folder' in manage_addFoo because this method
> many such variables. I just want to selectively get at the 'A_folder' from
> manage_addBar().
Well, I suspect your major problem is that (unless you omitted some "global"
statement) the A_folder you bind to in manage_addFoo only exists during the
method call, and is thereafter lost and garbage collected. You might want to
think about making A_folder an attribute of the instance, which you would do
by altering the assignment to:

    self.A_folder = ...

You can then simply refer to it as self.A_folder in the other method.

which-is-why-self-gets-passed-implicitly-ly y'rs  - steve

More information about the Python-list mailing list