473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

metaclass : parse all class once before doing anything else ?

Hi,

I have a much to smart problem for my brain.

Here is the deal :

I got a metaclass named Foo

Then I got two others classes:

class Bar(Foo):
pass

class Baz(Foo):
pass

I know how to add some attrs, methods to Bar and Baz when the module is
loaded but I need to do something more :

Before adding anything to these classes,
1 - I need to parse all defined Foo classes
2 - "sort" them
3 - parse this sorted list to add attrs and methods.

This seems to be really to clever for me ;-(

Any idea ?

Regards,

Laurent.
Jul 28 '06 #1
3 1296
Laurent Rahuel schrieb:
I got a metaclass named Foo

I have the impression that you are not talking about a meta-class, but a
normal class here.
Then I got two others classes:

class Bar(Foo):
pass

class Baz(Foo):
pass

I know how to add some attrs, methods to Bar and Baz when the module is
loaded but I need to do something more :

Before adding anything to these classes,
1 - I need to parse all defined Foo classes
2 - "sort" them
3 - parse this sorted list to add attrs and methods.

This seems to be really to clever for me ;-(

Any idea ?
Why do you want to do this? It is in that way not possible - python has
no preprocessing step that would allow this.

I suggest you explain to us what you are after here, and then we might
come up with a solution.

Diez
Jul 29 '06 #2

Laurent Rahuel wrote:
Hi,

I have a much to smart problem for my brain.

Here is the deal :

I got a metaclass named Foo

Then I got two others classes:

class Bar(Foo):
pass

class Baz(Foo):
pass

I know how to add some attrs, methods to Bar and Baz when the module is
loaded but I need to do something more :

Before adding anything to these classes,
1 - I need to parse all defined Foo classes
2 - "sort" them
3 - parse this sorted list to add attrs and methods.

This seems to be really to clever for me ;-(

Any idea ?

Regards,

Laurent.
I, like Diez am unsure of why you would need what you have asked for,
but maybe this will help.

You can keep track of all instances of a class by this kind of thing:
>>class C1(object):
.... inst = []
.... def __init__(self):
.... self.inst.append(self)
....
>>i1 = C1()
i2 = C1()
print i1,i2
<__main__.C1 object at 0x0128C970<__main__.C1 object at 0x0128CA50>
>>print C1.inst
[<__main__.C1 object at 0x0128C970>, <__main__.C1 object at
0x0128CA50>]
>>>
Jul 29 '06 #3

Paddy wrote:
Laurent Rahuel wrote:

Laurent.

I, like Diez am unsure of why you would need what you have asked for,
but maybe this will help.

You can keep track of all instances of a class by this kind of thing:
>class C1(object):
... inst = []
... def __init__(self):
... self.inst.append(self)
...
or list all subclasses with

print LaurentsPutativeMetaClass.__subclasses__()

me 3 for: not clear what you're getting at

Jul 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
33
by: Jacek Generowicz | last post by:
I would like to write a metaclass which would allow me to overload names in the definition of its instances, like this class Foo(object): __metaclass__ = OverloadingClass att = 1 att = 3
14
by: Pedro Werneck | last post by:
Hi I have a class A, with metaclass M_A, and class B, subclass of A, with metaclass M_B, subclass of M_A. A class C, subclass of B must have M_B or a subclass of it as metaclass, but what if...
9
by: Christian Eder | last post by:
Hi, I think I have discovered a problem in context of metaclasses and multiple inheritance in python 2.4, which I could finally reduce to a simple example: Look at following code: class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.