Having a mare with Classes

Steve Holden sholden at holdenweb.com
Wed Feb 13 07:29:24 EST 2002


"Graeme Matthew" <graeme.matthew at unite.com.au> wrote in ...
> Please can someone help, im having an absolute mare, I have Wesley Chuns
> book on core python programming and I cannot get casses to work, im just
> using a simple test from the examples in the book.
>
> OK I HAVE A CLASS PERSON
>
> class Person:
>
>      def printName(self):
>          print 'You printed it'
>
> I HAVE A SCRIPT:
>
> #!/usr/local/bin/Python2.2
>
>
> import sys
>
> sys.path.append('/www/cgi-bin')
>
> import Person
> person = Person() #### THIS IS THE PROBLEM
>
> person.printName()
>
> I keep on getting this error:
>
> #! /usr/local/bin/Python2.2
>
>
> TypeError: call or non function (type module)
>
Because you define the Person class in a Person module, which you then
import into your main script, you must refer to it as Person.Person (module
name qualified by class name: each module is a Python namespace). So the
error message is arising because you are trying to call a module (Person).

Replace the line I marked with

    person = Person.Person()

and all should be (relatively) well. Now go, my son, and sin no more :-)

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on c.l.py







More information about the Python-list mailing list