Private data

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Mar 19 05:09:09 EDT 2007


Dustan a écrit :
> http://dustangroups.googlepages.com/privateattributesinpython
> 
> This is something that I just threw together this morning, after a
> eureka moment. It's a way of creating private class attributes

What for ? We already have one: prefix 'private' names with a single 
underscore.

> and
> static function variables (I'm not 100% sure if that's the correct
> terminology, but you get what I mean).

def somefunc(param, _statics={}):
   # code here


> I haven't tried to create
> private instance attributes, mainly because it would just be too
> difficult, 

Same recipe as above : single leading underscore.

> and it would be awful syntax. I'm not considering actually
> using this, but I do have a couple questions about it.
> 
> 1. Has anyone else ever come up with something like this? I can't
> imagine I'm the only person who's ever thought of this.

With something like trying to forcefit access restriction in Python ? 
Nope, you're not the first one here. I've not seen anyone using such a 
thing in any of the projects I've worked on/with yet.




More information about the Python-list mailing list