469,332 Members | 6,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Private data

http://dustangroups.googlepages.com/...ibutesinpython

This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, 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.
2. Is it possible to hack into something like this? ie, would it be
possible to see and change these variables from client code (assuming
the data manager has been properly removed from sight, as shown on the
last line of class block TestPrivateClassAttributes)?

To avoid utter confusion, you may want to look at
TestPrivateClassAttributes before looking at the actual implementation
of PrivateDataEngine. If you're still confused, feel free to ask
what's going on here (and I'm open to suggestions on how to make it
clearer).

Mar 17 '07 #1
14 1324
En Sat, 17 Mar 2007 13:31:01 -0300, Dustan <Du**********@gmail.com>
escribió:
http://dustangroups.googlepages.com/...ibutesinpython

This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, and it would be awful syntax. I'm not considering actually
using this, but I do have a couple questions about it.
I feel so dumb, but I can't see how to use it, or what's for. Perhaps an
example?

--
Gabriel Genellina

Mar 18 '07 #2
On Sat, 17 Mar 2007 09:31:01 -0700, Dustan wrote:
http://dustangroups.googlepages.com/...ibutesinpython

This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, 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.
I've never seen anything like this before, but then I haven't gone looking
for anything like this.
2. Is it possible to hack into something like this? ie, would it be
possible to see and change these variables from client code (assuming
the data manager has been properly removed from sight, as shown on the
last line of class block TestPrivateClassAttributes)?
Yes.

First, an example of the code in action.
>>import PrivateAttributes
obj = PrivateAttributes.TestPrivateClassAttributes()
obj.getNumInstances()
1
>>another = PrivateAttributes.TestPrivateClassAttributes()
obj.getNumInstances()
2
>>athird = PrivateAttributes.TestPrivateClassAttributes()
athird.getNumInstances()
3

The getNumInstances method reports the number of instances of the
PrivateAttributes class. There's no obvious class attribute where this
count is being kept:
>>obj.__class__.__dict__.keys()
['__module__', 'getNumInstances', '__dict__', '__weakref__', '__doc__',
'__init__']
Here's how to hack it, and make it report wrong numbers.
>>c = obj.getNumInstances.func_closure
c[1].cell_contents.numInstances = -300

athird.getNumInstances()
-300
>>afourth = PrivateAttributes.TestPrivateClassAttributes()
athird.getNumInstances()
-299

So yes, it is absolutely hackable.

Now, I'm hardly a Python guru, but in about fifteen minutes I followed the
trail through the object chain, and found how to hack this. An real guru
would probably do it in three minutes.

I was helped a bit by having the source code. But even without the source
code, I reckon I could have done it in an hour or so, if I was motivated
enough. All the tools you need are a Python interactive session, the dir()
function and the dis module.

--
Steven

Mar 18 '07 #3
On Mar 18, 5:26 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 17 Mar 2007 13:31:01 -0300, Dustan <DustanGro...@gmail.com>
escribió:
http://dustangroups.googlepages.com/...ibutesinpython
This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, and it would be awful syntax. I'm not considering actually
using this, but I do have a couple questions about it.

I feel so dumb, but I can't see how to use it, or what's for. Perhaps an
example?

--
Gabriel Genellina
There are two examples - one demonstrating static function variables
and one demonstrating private class attributes. Both perform some kind
of counting. The function returns how many times it's been called.
Here it is:

@PrivateDataEngine(numCalls = 0)
def testPrivateStaticFunctionVariables(internalData):
"""returns the number of times this function has been called."""
internalData.numCalls += 1
return internalData.numCalls

There's a comment explaining how the decorator works on the page I
linked you to.

A common pythonic workaround for this is something like this:

def testMutableDefaultArgs(_cache = {'internalData':0}):
"""returns the number of times this function has been called."""
_cache['internalData'] += 1
return _cache['internalData']

The default argument only gets evaluated once, and since it's mutable
and being modified in the function, it magically becomes
{'internalData':1} after 1 call and {'internalData':1348372} after
1348372 calls.

The other example, explaining private class attributes, has a method
getNumInstances that returns how many instances have been created.
Here that is:

class TestPrivateClassAttributes(object):
# pca here obviously stands for Private Class Attributes.
pcaManager = PrivateDataEngine(numInstances = 0)

# Notice that the internal data is an implicit parameter that
comes first,
# even before the self parameter.
@pcaManager
def __init__(internalData, self):
internalData.numInstances += 1

@staticmethod
@pcaManager
def getNumInstances(internalData):
return internalData.numInstances

# Don't forget to delete the pcvManager, or it will have all been
in vain.
del pcaManager

I'm thinking this is going to look rather ugly when the text gets
wrapped; that's why I linked to an external page in the first place.

Notice it requires more advanced usage of the PrivateDataEngine if you
want multiple functions to have access to the same data, as you
normally would in a class.

Note also that the double-decorated method getNumInstances requires
that staticmethod be the first decorator. This is equivalent to the
code "getNumInstances = staticmethod(pcaManager(getNumInstances))". I
got an error when I tried it with pcaManager preceding staticmethod,
so my educated guess is that staticmethods are somehow specially
recognized by the class, and therefore they have to actually BE
staticmethods, not dressed over by a pcaManager.

Now that I think of it, for clarity, pcaManager may not have been a
good name for the function returned by PrivateDataEngine; pcaDecorator
would have been better, seeing as it IS a decorator. Perhaps I'll
change that soon.

The pythonic way would be:

class TestPythonsPrivateClassAttributes(object):
_numInstances = 0

def __init__(self):
# class attributes can be accessed from self.
self.numInstances += 1

@staticmethod
def getNumInstances(internalData):
return self.numInstances

It should immediately stick out as being much more concise
syntactically, and therefore much less bug-prone.

Obviously, these examples are a lot like "Hello, World!" in their
usefulness; one would very rarely want to track how many times a
function has been called.

Hope that helps.

Mar 18 '07 #4
On Mar 18, 7:06 am, Steven D'Aprano
<s...@REMOVE.THIS.cybersource.com.auwrote:
On Sat, 17 Mar 2007 09:31:01 -0700, Dustan wrote:
http://dustangroups.googlepages.com/...ibutesinpython
This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, 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.

I've never seen anything like this before, but then I haven't gone looking
for anything like this.
2. Is it possible to hack into something like this? ie, would it be
possible to see and change these variables from client code (assuming
the data manager has been properly removed from sight, as shown on the
last line of class block TestPrivateClassAttributes)?

Yes.

First, an example of the code in action.
>import PrivateAttributes
obj = PrivateAttributes.TestPrivateClassAttributes()
obj.getNumInstances()
1
>another = PrivateAttributes.TestPrivateClassAttributes()
obj.getNumInstances()
2
>athird = PrivateAttributes.TestPrivateClassAttributes()
athird.getNumInstances()

3

The getNumInstances method reports the number of instances of the
PrivateAttributes class. There's no obvious class attribute where this
count is being kept:
>obj.__class__.__dict__.keys()

['__module__', 'getNumInstances', '__dict__', '__weakref__', '__doc__',
'__init__']

Here's how to hack it, and make it report wrong numbers.
>c = obj.getNumInstances.func_closure
c[1].cell_contents.numInstances = -300
>athird.getNumInstances()
-300
>afourth = PrivateAttributes.TestPrivateClassAttributes()
athird.getNumInstances()

-299

So yes, it is absolutely hackable.
I did have a feeling that it was hackable, but had no idea how one
could possibly go about hacking it (I was starting to wonder of there
was a way to apply locals() and globals() on functions). But now I
(ehem) sorta know how it's done.
Now, I'm hardly a Python guru, but in about fifteen minutes I followed the
trail through the object chain, and found how to hack this. An real guru
would probably do it in three minutes.

I was helped a bit by having the source code. But even without the source
code, I reckon I could have done it in an hour or so, if I was motivated
enough. All the tools you need are a Python interactive session, the dir()
function and the dis module.
I have used all of those before, but I haven't been able to fully
understand the output of the dis module; maybe that's my problem.
--
Steven
Mar 18 '07 #5
On Mar 18, 7:17 am, "Dustan" <DustanGro...@gmail.comwrote:
On Mar 18, 5:26 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 17 Mar 2007 13:31:01 -0300, Dustan <DustanGro...@gmail.com>
escribió:
>http://dustangroups.googlepages.com/...ibutesinpython
This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes and
static function variables (I'm not 100% sure if that's the correct
terminology, but you get what I mean). I haven't tried to create
private instance attributes, mainly because it would just be too
difficult, and it would be awful syntax. I'm not considering actually
using this, but I do have a couple questions about it.
I feel so dumb, but I can't see how to use it, or what's for. Perhaps an
example?
--
Gabriel Genellina

There are two examples - one demonstrating static function variables
and one demonstrating private class attributes. Both perform some kind
of counting. The function returns how many times it's been called.
Here it is:

@PrivateDataEngine(numCalls = 0)
def testPrivateStaticFunctionVariables(internalData):
"""returns the number of times this function has been called."""
internalData.numCalls += 1
return internalData.numCalls

There's a comment explaining how the decorator works on the page I
linked you to.

A common pythonic workaround for this is something like this:

def testMutableDefaultArgs(_cache = {'internalData':0}):
"""returns the number of times this function has been called."""
_cache['internalData'] += 1
return _cache['internalData']

The default argument only gets evaluated once, and since it's mutable
and being modified in the function, it magically becomes
{'internalData':1} after 1 call and {'internalData':1348372} after
1348372 calls.

The other example, explaining private class attributes, has a method
getNumInstances that returns how many instances have been created.
Here that is:

class TestPrivateClassAttributes(object):
# pca here obviously stands for Private Class Attributes.
pcaManager = PrivateDataEngine(numInstances = 0)

# Notice that the internal data is an implicit parameter that
comes first,
# even before the self parameter.
@pcaManager
def __init__(internalData, self):
internalData.numInstances += 1

@staticmethod
@pcaManager
def getNumInstances(internalData):
return internalData.numInstances

# Don't forget to delete the pcvManager, or it will have all been
in vain.
del pcaManager

I'm thinking this is going to look rather ugly when the text gets
wrapped; that's why I linked to an external page in the first place.

Notice it requires more advanced usage of the PrivateDataEngine if you
want multiple functions to have access to the same data, as you
normally would in a class.

Note also that the double-decorated method getNumInstances requires
that staticmethod be the first decorator. This is equivalent to the
code "getNumInstances = staticmethod(pcaManager(getNumInstances))". I
got an error when I tried it with pcaManager preceding staticmethod,
so my educated guess is that staticmethods are somehow specially
recognized by the class, and therefore they have to actually BE
staticmethods, not dressed over by a pcaManager.

Now that I think of it, for clarity, pcaManager may not have been a
good name for the function returned by PrivateDataEngine; pcaDecorator
would have been better, seeing as it IS a decorator. Perhaps I'll
change that soon.

The pythonic way would be:

class TestPythonsPrivateClassAttributes(object):
_numInstances = 0

def __init__(self):
# class attributes can be accessed from self.
self.numInstances += 1

@staticmethod
def getNumInstances(internalData):
return self.numInstances

It should immediately stick out as being much more concise
syntactically, and therefore much less bug-prone.

Obviously, these examples are a lot like "Hello, World!" in their
usefulness; one would very rarely want to track how many times a
function has been called.

Hope that helps.
I forgot to note that the 'pythonic' ways are untested (and remain so,
as far as I know).

Mar 18 '07 #6
On Mar 18, 7:25 am, "Dustan" <DustanGro...@gmail.comwrote:
On Mar 18, 7:06 am, Steven D'Aprano
First, an example of the code in action.
>>import PrivateAttributes
>>obj = PrivateAttributes.TestPrivateClassAttributes()
>>obj.getNumInstances()
1
>>another = PrivateAttributes.TestPrivateClassAttributes()
>>obj.getNumInstances()
2
>>athird = PrivateAttributes.TestPrivateClassAttributes()
>>athird.getNumInstances()
3
The getNumInstances method reports the number of instances of the
PrivateAttributes class. There's no obvious class attribute where this
count is being kept:
>>obj.__class__.__dict__.keys()
['__module__', 'getNumInstances', '__dict__', '__weakref__', '__doc__',
'__init__']
Here's how to hack it, and make it report wrong numbers.
>>c = obj.getNumInstances.func_closure
>>c[1].cell_contents.numInstances = -300
>>athird.getNumInstances()
-300
>>afourth = PrivateAttributes.TestPrivateClassAttributes()
>>athird.getNumInstances()
-299
So yes, it is absolutely hackable.

I did have a feeling that it was hackable, but had no idea how one
could possibly go about hacking it (I was starting to wonder of there
was a way to apply locals() and globals() on functions). But now I
(ehem) sorta know how it's done.
Now, I'm hardly a Python guru, but in about fifteen minutes I followed the
trail through the object chain, and found how to hack this. An real guru
would probably do it in three minutes.
I was helped a bit by having the source code. But even without the source
code, I reckon I could have done it in an hour or so, if I was motivated
enough. All the tools you need are a Python interactive session, the dir()
function and the dis module.

I have used all of those before, but I haven't been able to fully
understand the output of the dis module; maybe that's my problem.
Alright, perhaps you can help me out with this learning curve here. I
have seen, but not worked with, some basic assembly code, so I think I
have a vague idea of what it all means, although I have a feeling it's
not all valid assembly (on any widely used machine).

First I dis.dis'd testPrivateStaticFunctionVariables:
>>dis.dis(testPrivateStaticFunctionVariables)
21 0 LOAD_DEREF 0 (func)
3 LOAD_DEREF 1 (internalData)
6 LOAD_FAST 0 (args)
9 CALL_FUNCTION_VAR 1
12 RETURN_VALUE

At first I was a little confused by this, because there's no increment
in sight, but then I realized it was dis.dis'ing the wrapper closure
in the internalDataDecorator closure in the PrivateDataEngine function
(and then I hit myself on the head and cried out "doh!"). So that
'code' is coming from this (taken out of closure):

def wrapper(*args):
return func(internalData, *args)

So, based on what you showed me, I found my way after some failed
tries to this:
>>dis.dis(testPrivateStaticFunctionVariables.func_ closure[0].cell_contents)
28 0 LOAD_FAST 0 (internalData)
3 DUP_TOP
4 LOAD_ATTR 0 (numCalls)
7 LOAD_CONST 1 (1)
10 INPLACE_ADD
11 ROT_TWO
12 STORE_ATTR 0 (numCalls)

29 15 LOAD_FAST 0 (internalData)
18 LOAD_ATTR 0 (numCalls)
21 RETURN_VALUE

That's coming from this:

@PrivateDataEngine(numCalls = 0)
def testPrivateStaticFunctionVariables(internalData):
"""returns the number of times this function has been called."""
internalData.numCalls += 1
return internalData.numCalls
Here's a few questions on this output, for which I would highly
appreciate some answers:

What's the difference between 'LOAD_DEREF', 'LOAD_FAST', and
'LOAD_CONST', and, as seen at http://docs.python.org/lib/module-dis.html,
'LOAD_GLOBAL'? I can imagine that 'LOAD_GLOBAL' loads a global, but
seeing as python is such a dynamic language, how exactly is it
supposed to distinguish between them?

I don't understand the following at all: 'DUP_TOP', 'ROT_TWO'. Any
pointers?

What does 'INPLACE_ADD' mean, if not in place addition, and if it is
in place addition, why does it need to 'STORE_ATTR' afterward?

Thanks for any help!
--
Steven
Mar 18 '07 #7
On Mar 18, 8:21 am, "Dustan" <DustanGro...@gmail.comwrote:
On Mar 18, 7:25 am, "Dustan" <DustanGro...@gmail.comwrote:
On Mar 18, 7:06 am, Steven D'Aprano
First, an example of the code in action.
>import PrivateAttributes
>obj = PrivateAttributes.TestPrivateClassAttributes()
>obj.getNumInstances()
1
>another = PrivateAttributes.TestPrivateClassAttributes()
>obj.getNumInstances()
2
>athird = PrivateAttributes.TestPrivateClassAttributes()
>athird.getNumInstances()
3
The getNumInstances method reports the number of instances of the
PrivateAttributes class. There's no obvious class attribute where this
count is being kept:
>obj.__class__.__dict__.keys()
['__module__', 'getNumInstances', '__dict__', '__weakref__', '__doc__',
'__init__']
Here's how to hack it, and make it report wrong numbers.
>c = obj.getNumInstances.func_closure
>c[1].cell_contents.numInstances = -300
>athird.getNumInstances()
-300
>afourth = PrivateAttributes.TestPrivateClassAttributes()
>athird.getNumInstances()
-299
So yes, it is absolutely hackable.
I did have a feeling that it was hackable, but had no idea how one
could possibly go about hacking it (I was starting to wonder of there
was a way to apply locals() and globals() on functions). But now I
(ehem) sorta know how it's done.
Now, I'm hardly a Python guru, but in about fifteen minutes I followed the
trail through the object chain, and found how to hack this. An real guru
would probably do it in three minutes.
I was helped a bit by having the source code. But even without the source
code, I reckon I could have done it in an hour or so, if I was motivated
enough. All the tools you need are a Python interactive session, the dir()
function and the dis module.
I have used all of those before, but I haven't been able to fully
understand the output of the dis module; maybe that's my problem.

Alright, perhaps you can help me out with this learning curve here. I
have seen, but not worked with, some basic assembly code, so I think I
have a vague idea of what it all means, although I have a feeling it's
not all valid assembly (on any widely used machine).

First I dis.dis'd testPrivateStaticFunctionVariables:
>dis.dis(testPrivateStaticFunctionVariables)

21 0 LOAD_DEREF 0 (func)
3 LOAD_DEREF 1 (internalData)
6 LOAD_FAST 0 (args)
9 CALL_FUNCTION_VAR 1
12 RETURN_VALUE

At first I was a little confused by this, because there's no increment
in sight, but then I realized it was dis.dis'ing the wrapper closure
in the internalDataDecorator closure in the PrivateDataEngine function
(and then I hit myself on the head and cried out "doh!"). So that
'code' is coming from this (taken out of closure):

def wrapper(*args):
return func(internalData, *args)

So, based on what you showed me, I found my way after some failed
tries to this:
>dis.dis(testPrivateStaticFunctionVariables.func_c losure[0].cell_contents)

28 0 LOAD_FAST 0 (internalData)
3 DUP_TOP
4 LOAD_ATTR 0 (numCalls)
7 LOAD_CONST 1 (1)
10 INPLACE_ADD
11 ROT_TWO
12 STORE_ATTR 0 (numCalls)

29 15 LOAD_FAST 0 (internalData)
18 LOAD_ATTR 0 (numCalls)
21 RETURN_VALUE

That's coming from this:

@PrivateDataEngine(numCalls = 0)
def testPrivateStaticFunctionVariables(internalData):
"""returns the number of times this function has been called."""
internalData.numCalls += 1
return internalData.numCalls

Here's a few questions on this output, for which I would highly
appreciate some answers:

What's the difference between 'LOAD_DEREF', 'LOAD_FAST', and
'LOAD_CONST', and, as seen athttp://docs.python.org/lib/module-dis.html,
'LOAD_GLOBAL'? I can imagine that 'LOAD_GLOBAL' loads a global, but
seeing as python is such a dynamic language, how exactly is it
supposed to distinguish between them?

I don't understand the following at all: 'DUP_TOP', 'ROT_TWO'. Any
pointers?

What does 'INPLACE_ADD' mean, if not in place addition, and if it is
in place addition, why does it need to 'STORE_ATTR' afterward?

Thanks for any help!
If this had been on any other usenet group, someone would have RTFM'd
me to hell.
http://docs.python.org/lib/bytecodes.html
I might still have some more questions later, but for now, I'll look
at this.
--
Steven

Mar 18 '07 #8
En Sun, 18 Mar 2007 10:21:27 -0300, Dustan <Du**********@gmail.com>
escribió:
>>>dis.dis(testPrivateStaticFunctionVariables)
21 0 LOAD_DEREF 0 (func)
3 LOAD_DEREF 1 (internalData)
6 LOAD_FAST 0 (args)
9 CALL_FUNCTION_VAR 1
12 RETURN_VALUE

What's the difference between 'LOAD_DEREF', 'LOAD_FAST', and
'LOAD_CONST', and, as seen at http://docs.python.org/lib/module-dis.html,
'LOAD_GLOBAL'? I can imagine that 'LOAD_GLOBAL' loads a global, but
seeing as python is such a dynamic language, how exactly is it
supposed to distinguish between them?
The Python interpreter executes a stack-based machine. Look at
Python/compile.c for the code generation and Python/ceval.c for the code
execution.
LOAD_CONST pushes a constant onto the stack (all constants are previously
built and stored as attribute co_consts of the code object). LOAD_FAST and
LOAD_GLOBAL pushes a local or global variable reference. (The compiler
knows whether a name is local or not, just by lexical analysis).
LOAD_DEREF appears to be used for accessing variables inside closures, I'm
not sure.
I don't understand the following at all: 'DUP_TOP', 'ROT_TWO'. Any
pointers?
They manipulate the stack. DUP_TOP duplicates the top entry; ROT_TWO swaps
the two top entries.
What does 'INPLACE_ADD' mean, if not in place addition, and if it is
in place addition, why does it need to 'STORE_ATTR' afterward?
That corresponds to A += B. The compiler can't know if A has or not an
__iadd__ method; even if A implements __iadd__, that method could return a
different object, not always A (it *may* try to do the operation inplace,
but that might not always be possible). When the inplace method is not
implemented, __add__ is used (so effectively A += B is computed as A = A+B)

--
Gabriel Genellina

Mar 19 '07 #9
Dustan a écrit :
http://dustangroups.googlepages.com/...ibutesinpython

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.

Mar 19 '07 #10
On Mar 19, 4:09 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Dustan a écrit :
http://dustangroups.googlepages.com/...ibutesinpython
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.
You ignored certain parts of my post, like "I'm not considering
actually using this, but I do have a couple questions about it"; I
assume that means you're not even going to begin to attempt to answer
my queries. Likewise, you ignored a similar message on the page I
linked to. I already knew about everything you told me.

With all this active ignoring, I get the feeling you're not even
trying to respond to my questions. So why respond in the first place?
Were you trying to be hostile? Because I can't see any other intent
for your post.

Mar 19 '07 #11
Dustan a écrit :
On Mar 19, 4:09 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
>Dustan a écrit :
>>http://dustangroups.googlepages.com/...ibutesinpython
This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes
(snip)
>>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.

You ignored certain parts of my post, like "I'm not considering
actually using this, but I do have a couple questions about it"; I
assume that means you're not even going to begin to attempt to answer
my queries. Likewise, you ignored a similar message on the page I
linked to. I already knew about everything you told me.

With all this active ignoring, I get the feeling you're not even
trying to respond to my questions. So why respond in the first place?
Were you trying to be hostile?

Because I can't see any other intent
for your post.
I didn't missed the "I'm not considering actually using this" part, but
I missed the note on the page - and I apologize if you felt offended by
my remarks, which were effectivly a bit on the reactive side. Still
there was an implied question : *why* trying to implement access
restriction in Python ?

Mar 19 '07 #12
Dustan a écrit :
http://dustangroups.googlepages.com/...ibutesinpython
May I report a small typo ?

"""
def interanalDataDecorator(func):
"""

Talking about private attributes... !-)
Mar 19 '07 #13
On Mar 19, 3:06 pm, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
Dustan a écrit :
http://dustangroups.googlepages.com/...ibutesinpython

May I report a small typo ?
Absolutely. I might even fix it.
"""
def interanalDataDecorator(func):
"""

Talking about private attributes... !-)
Thanks.

Mar 19 '07 #14
On Mar 19, 7:31 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Dustan a écrit :
On Mar 19, 4:09 am, Bruno Desthuilliers <bruno.
42.desthuilli...@wtf.websiteburo.oops.comwrote:
Dustan a écrit :
>>http://dustangroups.googlepages.com/...ibutesinpython
This is something that I just threw together this morning, after a
eureka moment. It's a way of creating private class attributes
(snip)
>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.
You ignored certain parts of my post, like "I'm not considering
actually using this, but I do have a couple questions about it"; I
assume that means you're not even going to begin to attempt to answer
my queries. Likewise, you ignored a similar message on the page I
linked to. I already knew about everything you told me.
With all this active ignoring, I get the feeling you're not even
trying to respond to my questions. So why respond in the first place?
Were you trying to be hostile?
Because I can't see any other intent
for your post.

I didn't missed the "I'm not considering actually using this" part, but
I missed the note on the page - and I apologize if you felt offended by
my remarks, which were effectivly a bit on the reactive side.
Apology accepted.
Still
there was an implied question : *why* trying to implement access
restriction in Python ?
My curiosity gets piqued every once in a second or so. This just
happened to be one of those occasions. I assume you read my questions;
I was curious to see if anyone else had ever thought up something as
utterly twisted and conniving as this, and how one could go about
hacking into such a construct (I might not have said it explicitly,
but I was pretty sure that there had to be a way, because it just
wouldn't be python if there wasn't a way of getting into it).

Mar 19 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Richard Webb | last post: by
2 posts views Thread by ma740988 | last post: by
12 posts views Thread by Preets | last post: by
86 posts views Thread by jopperdepopper | last post: by
63 posts views Thread by time.swift | last post: by
6 posts views Thread by zfareed | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.