Class Help
Jean-François Doyon
jfdoyon at methane.ca
Sat Oct 1 19:13:20 EDT 2005
You have to crate an instanciation of the class before you can use one.
So you want to do:
instance = Xyz()
instance.y()
You won't get any output though, might want to do:
class Xyz:
def y(self):
print 'y worked!'
it's more satisfying :)
Basically, look into the difference between a class, and the INSTANCE of
a class.
Cheers,
J.F.
Ivan Shevanski wrote:
> To continue with my previous problems, now I'm trying out classes. But
> I have a problem (which I bet is easily solveable) that I really don't
> get. The numerous tutorials I've looked at just confsed me.For intance:
>
>>>> class Xyz:
>
> ... def y(self):
> ... q = 2
> ...
>
>>>> Xyz.y()
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: unbound method y() must be called with Xyz instance as first
> argument
> (got nothing instead)
>
>
> So. . .What do I have to do? I know this is an extremley noob question
> but I think maybe if a person explained it to me I would finally get it =/
>
>
> thanks in advance,
>
> -Ivan
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's
> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
More information about the Python-list
mailing list