Defining class files

Neil Benn neil.benn at
Wed Mar 28 15:04:16 CEST 2001


            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,

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 - is this the problem, should
class files have different terminaters in their filename??

    Any/all help would be most appreciated!!


Neil Benn
Automation Informatics Scientist
Cambridge Antibody Technology

More information about the Python-list mailing list