[Tutor] is it possible to call a setter property during classinstantiation?

Alan Gauld alan.gauld at btinternet.com
Fri Aug 13 10:13:11 CEST 2010


"Serdar Tumgoren" <zstumgoren at gmail.com> wrote

> Does anyone know if it's possible to call a property setter inside 
> of a
> class's init method?  Below is a code sample of what I'm trying to 
> do.

Yes and that bit has been answered.
But...

> I have a class with an init method that is getting bloated with
> error-checking guard clauses.

Thats very strange. We don't usually have to check types in Python,
it is a dynamic language and we can use duck-typing and exceptions
so we don't usually care too much about types. Are you sure you
really need all that type checking code? Or are you simply
carrying bad habits over from statically typed programming
experience?

I can't tell the context so it may be that you really do need to check
a lot of types, but it is quite unusual and does usually lead to a lot 
of
extra work. Python is not Java or C++ etc...

Just a thought,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list