Bad form to access a *private variable* like _foo?
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Tue May 6 03:36:36 EDT 2008
seberino at spawar.navy.mil a écrit :
> Bad form to access a *private variable* like _foo?
In this case, this would be spelled "protected" - or even better
"implementation". And the contract is: nothing prevent you to access
implementation attributes, but then you're on your own if anything breaks.
> The reason I'm asking is that TurboGears/SQLObject mobel objects have
> an attribute called "_connection" that must be used to manually commit
> database stuff....
>
> e.g. MyObject._connection.commit()
>
> It bugs me. I don't know if it is a stylistic faux pas or not.
>
> Is it?
The way you wrote it here, yes. If there's no official way to do the
same operation and you have a real use case for it - in which case you
may want to add a commit() method to SQLObject's model base class and
submit the patch to SQLObject's maintainer. But I strongly suspect
there's a better way to handle this case in SQLObject's API.
More information about the Python-list
mailing list