Defining class files

Neil Benn neil.benn at cambridgeantibody.com
Wed Mar 28 08:04:16 EST 2001


Hello,

            Sorry to ask such a basic question but -

I'm wokring through the tutorial and have reached the section on classes in
Python.  Working through the example on classes I have entered the class
using the interpreter:-

class MyClass:
    "A simple example class"
    i = 12345
    def f(x):
        return 'hello world'

    This worked fine when I typed:-

>>> x=MyClass()
>>> x.f()
'Hello World'

    However, I then tried to write the class as an external text file,
using:-

class YourClass:
    "A simple example class"
    i = 12345
    def f(x):
        return 'hello world'

    I then imported the class, tried to assign the class and ivoke a method
:-

>>> 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>

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

    Any/all help would be most appreciated!!

Cheers,

Neil Benn
Automation Informatics Scientist
Cambridge Antibody Technology
Cambs
UK





More information about the Python-list mailing list