Defining class files

Alex Martelli aleaxit at yahoo.com
Thu Mar 29 08:39:22 EST 2001


"Neil Benn" <neil.benn at cambridgeantibody.com> wrote in message
news:3ac33343$0$12248$ed9e5944 at reading.news.pipex.net...
    [snip]
>     However, I then tried to write the class as an external text file,
    [snip]
>     I then imported the class, tried to assign the class and ivoke a
method

Not really -- you imported the MODULE which contains the class:

> >>> y = YourClass()
> Traceback (innermost last):
>   File "<console>", line 1,
> TypeError: call of non-func
>
>     This seemed a bit strange, so I investigated the Your class and it
> seemed to be a module.
>
> >>> YourClass
> <module YourClass at 2584541>

So, YourClass is a module object -- it no doubt refers to a
class object (called, from the outside, YourClass.YourClass).

>     The text file is saved as YourClass.py - is this the problem, should
> class files have different terminaters in their filename??

No problem in having the same name.  But, after an
    import YourClass
you must use YourClass.YourClass to refer to the
_class_ object; or else (normally less advisable),
    from YourClass import YourClass
will let you use just YourClass to refer to the
class object (but you have no name for the module
object, which in some cases is helpful to use).


Alex






More information about the Python-list mailing list