instance creation

Erik Max Francis max at alcyone.com
Tue Sep 24 05:05:14 EDT 2002


Paul MG wrote:

> - Having two constructors seems to be illegal - or at least the second
> overwrites the first.

That's correct.  Python does not allow overloading functions with the
same name but different argument lists.

> - Assigning to 'self' in the load method seems to really not work!

Indeed, and you shouldn't have expected it to.  self is a variable like
anything else, and in Python, variables are merely bindings, not
reseatable references.  Assignment just rebinds the name, it doesn't
affect the bound object.

> - Putting the create() method outside of the class works fine - but I
> want it to be a class method on Appointment, goddammit!:) Is there no
> way to do this?

Later versions of Python have a staticmethod function for this.  You'd
use it like this:

	class C:
	    def f(x): # note, no self argument
	        ...
	    f = staticmethod(f)

This allows f to be called as C.f or even c.f, if c were an instance of
C.

> Any help would be appreciated, basically i am looking for the python
> idiom to do this, as my C++ and Smalltalk idiom's clearly aren't in
> the grain of the language!

Depending on your tastes, a module function might make more sense.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ I wish you well but / Right now I'm just bitter
\__/ Chante Moore
    Alcyone Systems' CatCam / http://www.catcam.com/
 What do your pets do all day while you're at work?  Find out.



More information about the Python-list mailing list