Thank you for your thoughts.
I'm trying to migrating en existing python2 api,
which has been build using boost::python with pure python3 code.
All of the py2 classes do have these additional properties names and values.
You are right, using dict(Ordinal.__members__) for names
could have been used
Eko palypse wrote:
> I'm fairly new when it comes to metaclass programming and therefore the
> question whether the following makes sense or not.
>
> The goal is to have two additional class properties which return a
> dictionary name:class_attribute and value:class_attribute for an IntEnum
> cla
W dniu 23.12.2016 o 15:14, Ian Kelly pisze:
(...)
cls.added_in_init = 'test'
Man, you are awsome genius! Finally somebody was able to explain me what
is the power of __new__ and difference between __init__ !!!
So what I wanted to achieve was adding some new attributes to the class
ins
On Fri, Dec 23, 2016 at 5:14 AM, Mr. Wrobel wrote:
> Hi,thanx for answers, let's imagine that we want to add one class attribute
> for newly created classess with using __init__ in metaclass, here's an
> example:
>
> #!/usr/bin/env python
>
> class MetaClass(type):
> # __init__ manipulation:
>
W dniu 21.12.2016 o 02:51, Ethan Furman pisze:
On 12/20/2016 03:39 PM, Ben Finney wrote:
"Mr. Wrobel" writes:
Quick question, can anybody tell me when to use __init__ instead of
__new__ in meta programming?
Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the
On 12/20/2016 03:39 PM, Ben Finney wrote:
"Mr. Wrobel" writes:
Quick question, can anybody tell me when to use __init__ instead of
__new__ in meta programming?
Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the storage, determining the type, etc. — anything
On 12/20/2016 03:26 PM, Ian Kelly wrote:
... The latter is interesting mostly because it allows you to set the
__slots__ or do something interesting with the __prepare__ hook
(although the only interesting thing I've ever seen done with
__prepare__ is to use an OrderedDict to preserve the the de
"Mr. Wrobel" writes:
> Quick question, can anybody tell me when to use __init__ instead of
> __new__ in meta programming?
Use ‘__new__’ to do the work of *creating* one instance from nothing;
allocating the storage, determining the type, etc. — anything that will
be *the same* for every instance
On Tue, Dec 20, 2016 at 2:04 PM, Mr. Wrobel wrote:
> Hi,
>
> Quick question, can anybody tell me when to use __init__ instead of __new__
> in meta programming?
>
> I see that __new__ can be used mostly when I want to manipulate with class
> variables that are stored into dictionary.
>
> But when t
On Mar 4, 12:51 am, Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> On Mar 4, 6:31 am, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote:
>
> > > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote:
>
> > > > What are metaclasses?
>
> > > Depends on whether you want
On Mar 4, 6:31 am, [EMAIL PROTECTED] wrote:
> On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote:
>
> > > What are metaclasses?
>
> > Depends on whether you want to be confused or not. If you do, look at
> > this old but still head bursting
On Mar 3, 10:01 pm, Benjamin <[EMAIL PROTECTED]> wrote:
> On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote:
>
> > What are metaclasses?
>
> Depends on whether you want to be confused or not. If you do, look at
> this old but still head bursting
> essay:http://www.python.org/doc/essays/metaclasses/.
>
>
On Mar 3, 7:12 pm, [EMAIL PROTECTED] wrote:
> What are metaclasses?
Depends on whether you want to be confused or not. If you do, look at
this old but still head bursting essay:
http://www.python.org/doc/essays/metaclasses/.
Basically, the metaclass of a (new-style) class is responsible for
crea
On Mar 3, 8:22 pm, "Daniel Fetchinson" <[EMAIL PROTECTED]>
wrote:
> > What are metaclasses?
>
> http://www.google.com/search?q=python+metaclass
>
> HTH,
> Daniel
Not satisfied.
http://en.wikipedia.org/wiki/Metaclass#Python_example
That's a limitation. The constructor can omit the superclass cal
> What are metaclasses?
http://www.google.com/search?q=python+metaclass
HTH,
Daniel
--
http://mail.python.org/mailman/listinfo/python-list
En Mon, 03 Sep 2007 07:39:05 -0300, km <[EMAIL PROTECTED]>
escribi�:
> But why does it show varied difference in the time between a and b
> instance creations when __metaclass__ hook is used and when not used in
> class Y ? I dont understand that point !
What do you expect from a._created, b.
Hi,
But why does it show varied difference in the time between a and b
instance creations when __metaclass__ hook is used and when not used in
class Y ? I dont understand that point !
KM
On 9/1/07, Michele Simionato <[EMAIL PROTECTED]> wrote:
>
> On Sep 1, 6:07 pm, Steve Holden <[EMAIL PROTECTE
On Sep 1, 6:07 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> Debugging with Wing IDE and examining the classes at a breakpoint shows
> this to be true (even after Y's __metaclass__ assignment is commented out):
>
> >>> X.__metaclass__
>
> >>> Y.__metaclass__
>
> >>>
For the benefit of the
km wrote:
> Hi all,
>
> I have extended a prototype idea from Alex Martelli's resource on
> metaclasses regarding time stamping of instances.
>
>
> import time
> class Meta(type):
> start = time.time()
> def __call__(cls, *args, **kw):
> print 'Meta start time %e'%cls.start
>
Lenard Lindstrom <[EMAIL PROTECTED]> wrote:
> I don't know if C asserts are active in release Python, but for
> new-style classes one thing that happens during attribute lookup is that
> an object's class is asserted to be an instance of type.
Thank's for the explanation. My Linux distribution
Mirko Dziadzka wrote:
> Hi all
>
> I'm playing around with metaclasses and noticed, that there is small
> but mesurable a performance difference in the code shown below. With a
> more complex example I get a 5 percent performance penalty for using a
> metaclass. Until today I assumed, that a meta
Peter Otten wrote:
> You determine the factory Python uses to
> make a class by adding
>
> __metaclass__ = factory
>
> to the class body, so you'll probably end with something like
>
> class ProducerHandlerType(type):
> # your code
>
> class A:
> __metaclass__ = ProducerHandlerType
>
> Without looking into the details -- the (subclass of) type is meant to be
> the class of the class, or the other way round, your normal classes are
> instances of (a subclass of) type. You determine the factory Python uses to
> make a class by adding
>
> __metaclass__ = factory
>
> to the class
Laszlo Nagy wrote:
> I would like to create a hierarchy classes, where the leaves have a
> special attribute called "producer_id". In addition, I would like to
> have a function that can give me back the class assigned to any
> producer_id value. I tried to implement this with a metaclass, but I
>
Létező wrote:
> I use Python 2.4.4. Please read the code below:
>
> ---
> from new import classobj
>
> def mymeta(name,bases,clsdict):
> print 'meta: %s'%name
> return classobj(name,bases,clsdict)
>
> class A(object):
> __metacl
Létez? wrote:
> I use Python 2.4.4. Please read the code below:
>
> ---
> from new import classobj
>
> def mymeta(name,bases,clsdict):
> print 'meta: %s'%name
> return classobj(name,bases,clsdict)
mymeta is not a class.
> class A
On Tuesday 27 September 2005 00:22, Michele Simionato wrote:
> It is not that easy, but you can leverage on my decorator module
> which does exactly what you want:
> http://www.phyast.pitt.edu/~micheles/python/decorator.zip
Excellent. Thank you :-).
- Michael
--
http://mail.python.org/mailman/li
Michael Ekstrand ha scritto:
> One issue remains in this function: my method's signature is lost when
> synchronized is applied (at least as somemeth=synchronized(somemeth);
> I'm currently in a 2.3 environment that doesn't have the decorator
> syntax, but my understanding is that makes no differe
On Sep 26, 2005, at 4:21 PM, Scott David Daniels wrote:
> Unnecessarily holding a lock while acquiring another can be a nasty
> source of deadlock or at least delay. Another source of problems is
> holding a lock because an exception skipped past the release code.
I had thought of part of that af
Michael Ekstrand wrote:
> Something like this (not yet tested):
>
> import threading
> global_lock = threading.Lock()
> def synchronized(meth):
> def inner(self, *args, **kwargs):
> try:
> self._sync_lock.acquire()
> except AttributeError:
> global_lock.
On Sep 26, 2005, at 2:16 PM, Tom Anderson wrote:
> You could define a meta-lock, and use that to protect the
> lock-installation action.
Something like this (not yet tested):
import threading
global_lock = threading.Lock()
def synchronized(meth):
def inner(self, *args, **kwargs):
On Mon, 26 Sep 2005, Jp Calderone wrote:
> On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng <[EMAIL PROTECTED]> wrote:
>> You could do it with a metaclass, but I think that's probably overkill.
>>
>> It's not really efficient as it's doing test/set of an RLock all the
>> time, but hey - you didn't a
Hmmm well that's obvious enough. This is why I shouldn't write code off the cuff on c.l.p :)OTOH - if I just assign the RLock in the base classes initializer, is there any problem?vic
On 9/26/05, Jp Calderone <[EMAIL PROTECTED]> wrote:
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng <[EMAIL
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng <[EMAIL PROTECTED]> wrote:
>You could do it with a metaclass, but I think that's probably overkill.
>
>It's not really efficient as it's doing test/set of an RLock all the
>time, but hey - you didn't ask for efficient. :)
There's a race condition in t
On Sunday 25 September 2005 22:30, Victor Ng wrote:
> You could do it with a metaclass, but I think that's probably
> overkill.
OK. And thanks for the example :-). It looks simple enough... I didn't
think the solution would be overly complex. And the RLock makes it
easier than I anticipated - wa
You could do it with a metaclass, but I think that's probably overkill.
It's not really efficient as it's doing test/set of an RLock all the
time, but hey - you didn't ask for efficient. :)
1 import threading
2
3 def synchronized(func):
4 def innerMethod(self, *args,
Jan-Ole Esleben wrote:
> Hi!
>
> I've just posted a question about metaclasses in ZOPE on the ZOPE
> list, and one of the replies said that metaclasses (at least
> "painless" metaclasses) cannot be used without new-style classes (or
> rather, that they don't work where you cannot explicitly use ne
Correct me if I'm wrong, but I think the OP was asking if metaclasses
work with old-style classes, not new-style.
[EMAIL PROTECTED] wrote:
> This may be a limitation Zope imposes.
>
> I wrote this program:
> #---
> class M(type):
This may be a limitation Zope imposes.
I wrote this program:
#---
class M(type):
def __new__(*args):
print "new M", args
class T(object):
__metaclass__ = M
#
On Thu, 4 Aug 2005 17:53:28 +0200, Jan-Ole Esleben <[EMAIL PROTECTED]> wrote:
>Thanks! It's a bit icky, yes, but I've been so wrapped up in
>complicated thinking that I didn't see this. It's actually quite an
>OK solution (I need it because I have an internal representation for
>method interfaces
Thanks! It's a bit icky, yes, but I've been so wrapped up in
complicated thinking that I didn't see this. It's actually quite an
OK solution (I need it because I have an internal representation for
method interfaces that needs to be saved somewhere without the user
having to worry about it, and wi
Jan-Ole Esleben wrote:
>Yes, that works, but it is unfortunately not an option (at least not a
>good one).
>
>Is there no way to create a class variable that exists during
>definition of the class? (I cannot imagine there isn't, since
>technically it's possible and manually it can be done...)
>
>O
Yes, that works, but it is unfortunately not an option (at least not a
good one).
Is there no way to create a class variable that exists during
definition of the class? (I cannot imagine there isn't, since
technically it's possible and manually it can be done...)
Ole
> classvar is defined AFTER
Christopher Subich wrote:
> Jan-Ole Esleben wrote:
>
>> class Meta(type):
>> def __new__(cls, name, bases, d):
>> d['classvar'] = []
>> return type.__new__(cls, name, bases, d)
>
>
> The problem is that __new__ is called upon object construction, not
> class definition, but you're try
Jan-Ole Esleben <[EMAIL PROTECTED]> writes:
> Hi!
>
> I am new to this list, and maybe this is a stupid question, but I
> can't seem to find _any_ kind of answer anywhere.
>
> What I want to do is the following:
> I want to insert a class variable into a class upon definition and
> actually use it
I thought __new__ was called upon construction of the _class_ object
that "Meta" is the type of. Then it would be available at the time of
the definition of my class. Or am I mistaken?
Ole
2005/8/4, Christopher Subich <[EMAIL PROTECTED]>:
> Jan-Ole Esleben wrote:
> > class Meta(type):
> > def _
Jan-Ole Esleben wrote:
> class Meta(type):
> def __new__(cls, name, bases, d):
> d['classvar'] = []
> return type.__new__(cls, name, bases, d)
The problem is that __new__ is called upon object construction, not
class definition, but you're trying to set the class variables at
definitio
Bob Cowdery wrote:
> Thanks for your help Robert. I'm still not
> understanding what I am seeing. I've forgotten
> about the objective for the moment. I just want
> to understand metaclasses.
All right; then I'll skip the speech about how metaclasses are not the solution
you're looking for. ;) Th
Title: RE: Metaclasses
Shalabh
Yes I am realising there are variaous ways to achieve the same end. I guess I am in research mode at the moment and understanding what metaclasses can do is important even if I end up not using them. There is another thread on this question where I am trying
Title: RE: Metaclasses
Robert Brewer wrote:
>Okay. It depends on where you're getting that capability information from, but the simplest approach I can >
>think of would be to stick it in the class:
>
>class API(object):
> __metaclass__ = MetaAPI
>
>
[EMAIL PROTECTED] wrote:
I am trying to build a capability based API. That is, an instance of the
api will reflect the capabilities of some underlying services.
The question I'd ask at this point is - does the term 'instance of the
API' correspond to a Python class, or an instance of the class th
Bob Cowdery wrote:
> What I want to do is when
>
> class API(object):
> __metaclass__ = MetaAPI
>
> is created that MetaAPI generates attributes from a given
> capability map and not the one it picked up on 'import'.
Okay. It depends on where you're getting that capability information from,
Title: RE: Metaclasses
Robert
Yes you understand exectly what I am trying to do, my test code was not much more than you show. You are right that to do the simple thing of adding attributes I can do that in-line as it were but there may be other customisations that I want to do. I am
Bob Cowdery wrote:
> I am trying to build a capability based API. That is,
> an instance of the api will reflect the capabilities
> of some underlying services. I could have several
> different instances of the api concurrently running
> against different back end services. A ui applet will
> bin
54 matches
Mail list logo