Trying to print from inside a method

AWasilenko at gmail.com AWasilenko at gmail.com
Sun Mar 18 20:08:32 EDT 2007


On Mar 18, 7:32 pm, a... at mac.com (Alex Martelli) wrote:
> Here, the message1 and message2 names are LOCAL variables of the
> respective methods: each disappear as soon as its method ends.
>
> If you want to make them into INSTANCE attributes, so they'll stick
> around for later, assign to self.message1 and self.message2 instead (and
> of course use these composite names too if need be).

Ah ha, the nugget of info I was forgetting!  Looking back now I can
see why the
author used the self.whatever, and why my code is not working.  When
I'm reading along
all his code looks find and dandy, makes perfect sense; but soon as I
try to do
something on my own quickly find that my understanding of how things
work is very
porous :)

> This would be pretty weird, but legal Python.
> Weirder and weirder, but still legal Python.

This is usually how most of my code turns out :(  I'm afraid if I ever
learn enough
to make a serious program I will be burned at the stake for such un-
pythonic practices :P




More information about the Python-list mailing list