Simple Python class questions

Cédric Lucantis omer at no-log.org
Thu Jun 19 08:14:02 EDT 2008


Le Thursday 19 June 2008 13:54:03 John Dann, vous avez écrit :
> A Python newbie, but some basic understanding of how classes, objects
> etc work in eg VB.Net. However, I'm struggling a little to translate
> this knowledge into the Python context.
>
> Maybe I could provide some outline code as an illustration:
>
> Let's say I define the class in a module called comms.py. The class
> isn't really going to inherit from any other class (except presumably
> in the most primitive base-class sense, which is presumably automatic
> and implicit in using the class keyword).

No it's not :) It is recommended to always use new-style classes, and thus to 
give the object base explicitely :

class serial_link (object) :
	...

see http://docs.python.org/ref/node33.html

> print serlink.openPort
>

You just forgot the (), so you're printing the method object itself without 
calling it : print serlink.openPort()

-- 
Cédric Lucantis



More information about the Python-list mailing list