How to organise classes and modules

Ilkka Poutanen etu.suku at iki.fi.invalid
Mon May 15 07:35:13 EDT 2006


On 2006-05-15, Alex <mizipzor at gmail.com> wrote:
>>>> import Foo
>>>> Foo.Foo.bar()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: unbound method bar() must be called with Foo instance as
> first argument (got nothing instead)
>
> ...
>
> One thing that I tried that worked ok was this:
>
>>>> import Foo
>>>> instance=Foo.Foo()
>>>> instance.bar()
> hello world
>
> But in my opinion, this is very ugly. Especially if the class names

Are you sure you understand object-oriented programming? Reading the
Python tutorial[1] and re-reading the above error messages should clue
you in to what you're doing wrong. To put it simply, the whole point of
classes is that you create instances of them, each having their own
internal state, and then invoke their methods to accomplish whatever it
is that you want your program to accomplish.

1. http://docs.python.org/tut/


-- 
Ilkka Poutanen [http://ipo.iki.fi/]
And unto this, Conan;



More information about the Python-list mailing list