Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > CONSTRUCT - Adding Functionality to the Overall System

Reply
Thread Tools

CONSTRUCT - Adding Functionality to the Overall System

 
 
Ilias Lazaridis
Guest
Posts: n/a
 
      09-17-2006
I understand that I can use __metaclass__ to create a class which
modifies the behaviour of another class.

How can I add this metaclass to *all* classes in the system?

(In ruby I would alter the "Class" class)

..

http://lazaridis.com

 
Reply With Quote
 
 
 
 
Calvin Spealman
Guest
Posts: n/a
 
      09-17-2006
On 17 Sep 2006 09:22:16 -0700, Ilias Lazaridis <(E-Mail Removed)> wrote:
> I understand that I can use __metaclass__ to create a class which
> modifies the behaviour of another class.
>
> How can I add this metaclass to *all* classes in the system?
>
> (In ruby I would alter the "Class" class)


This is a terrible idea. When my, Joe Modulewriter, released my
library of AwesomeCoolClasses, i except my metaclass to be something
particular and if it starts getting wonky and I do anything hackery on
my end with the types, then the end-user's computer might 'splode!

What I am trying to say, is its a terrible idea to go changing other
peoples' classes at runtime without knowing the real affects of what
is going on. If you are just going to shoot yourself in the foot, why
should we even give you a gun?
 
Reply With Quote
 
 
 
 
Georg Brandl
Guest
Posts: n/a
 
      09-17-2006
Ilias Lazaridis wrote:
> I understand that I can use __metaclass__ to create a class which
> modifies the behaviour of another class.
>
> How can I add this metaclass to *all* classes in the system?
>
> (In ruby I would alter the "Class" class)


You'd have to set

__metaclass__ = whatever

at the top of each module whose classes are to get the new behavior.

You can't alter classes which you don't control or create in your code.

Georg
 
Reply With Quote
 
Damjan
Guest
Posts: n/a
 
      09-17-2006

>> I understand that I can use __metaclass__ to create a class which
>> modifies the behaviour of another class.
>>
>> How can I add this metaclass to *all* classes in the system?
>>
>> (In ruby I would alter the "Class" class)

>
> You'd have to set
>
> __metaclass__ = whatever
>
> at the top of each module whose classes are to get the new behavior.


I think '__metaclass__ = whatever' affects only the creation of classes that
would otherwise be old-style classes?

> You can't alter classes which you don't control or create in your code.


I remeber I've seen an implementation of import_with_metaclass somewhere on
IBM's developerworks. I didn't quite undersntad it though.



--
damjan
 
Reply With Quote
 
Ilias Lazaridis
Guest
Posts: n/a
 
      09-18-2006
Damjan wrote:
> >> I understand that I can use __metaclass__ to create a class which
> >> modifies the behaviour of another class.
> >>
> >> How can I add this metaclass to *all* classes in the system?
> >>
> >> (In ruby I would alter the "Class" class)

> >
> > You'd have to set
> >
> > __metaclass__ = whatever
> >
> > at the top of each module whose classes are to get the new behavior.

>
> I think '__metaclass__ = whatever' affects only the creation of classes that
> would otherwise be old-style classes?


It seems so:

http://mail.python.org/pipermail/pyt...ne/166572.html

> > You can't alter classes which you don't control or create in your code.

>
> I remeber I've seen an implementation of import_with_metaclass somewhere on
> IBM's developerworks. I didn't quite undersntad it though.


http://www-128.ibm.com/developerwork.../l-pymeta.html

I am not so much interested in old-style, as is start production with
python 2.4 (possibly even with python 2.5).

..

--
http://lazaridis.com

 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      09-18-2006
Ilias Lazaridis wrote:
> Damjan wrote:
>
>>>>I understand that I can use __metaclass__ to create a class which
>>>>modifies the behaviour of another class.
>>>>
>>>>How can I add this metaclass to *all* classes in the system?
>>>>
>>>>(In ruby I would alter the "Class" class)
>>>
>>>You'd have to set
>>>
>>>__metaclass__ = whatever
>>>
>>>at the top of each module whose classes are to get the new behavior.

>>
>>I think '__metaclass__ = whatever' affects only the creation of classes that
>>would otherwise be old-style classes?

>
>
> It seems so:
>
> http://mail.python.org/pipermail/pyt...ne/166572.html
>
>
>>>You can't alter classes which you don't control or create in your code.

>>
>>I remeber I've seen an implementation of import_with_metaclass somewhere on
>>IBM's developerworks. I didn't quite undersntad it though.

>
>
> http://www-128.ibm.com/developerwork.../l-pymeta.html
>
> I am not so much interested in old-style, as is start production with
> python 2.4 (possibly even with python 2.5).
>

The fact remains that you won't be able to affect the built-in classes
such as int and str - they are hard-coded in C (for CPython, at least),
and so their metaclass is also implied and cannot be changed.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

 
Reply With Quote
 
Paul McGuire
Guest
Posts: n/a
 
      09-18-2006
"Calvin Spealman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 17 Sep 2006 09:22:16 -0700, Ilias Lazaridis <(E-Mail Removed)>
> wrote:
>> I understand that I can use __metaclass__ to create a class which
>> modifies the behaviour of another class.
>>
>> How can I add this metaclass to *all* classes in the system?
>>
>> (In ruby I would alter the "Class" class)

>
> This is a terrible idea. When my, Joe Modulewriter, released my
> library of AwesomeCoolClasses, i except my metaclass to be something
> particular and if it starts getting wonky and I do anything hackery on
> my end with the types, then the end-user's computer might 'splode!
>
> What I am trying to say, is its a terrible idea to go changing other
> peoples' classes at runtime without knowing the real affects of what
> is going on. If you are just going to shoot yourself in the foot, why
> should we even give you a gun?


Reminds me of when I was learning Smalltalk, and modified printOn (ST's
equivalent of str()) of the root-of-all-classes object class. I don't
remember the exact error I made, but it was a mess undoing it!

-- Paul


 
Reply With Quote
 
Ilias Lazaridis
Guest
Posts: n/a
 
      09-19-2006
Steve Holden wrote:
> Ilias Lazaridis wrote:

....
> > http://www-128.ibm.com/developerwork.../l-pymeta.html
> >
> > I am not so much interested in old-style, as is start production with
> > python 2.4 (possibly even with python 2.5).
> >

>
> The fact remains that you won't be able to affect the built-in classes
> such as int and str - they are hard-coded in C (for CPython, at least),
> and so their metaclass is also implied and cannot be changed.


....except in C.

I assume the "root class" should be available/changeable in "C", too.

Do I have to change the sources directly, or does python provide
"C-level-extension/modication" mechanisms, which can be applied to
core-level classes, too?

Is the Python Object Model documented anywhere in a diagram, something
similar to this?:

http://case.lazaridis.com/wiki/RubyObjectModel

..

 
Reply With Quote
 
Calvin Spealman
Guest
Posts: n/a
 
      09-19-2006
On 18 Sep 2006 20:23:03 -0700, Ilias Lazaridis <(E-Mail Removed)> wrote:
> Steve Holden wrote:
> > Ilias Lazaridis wrote:

> ...
> > > http://www-128.ibm.com/developerwork.../l-pymeta.html
> > >
> > > I am not so much interested in old-style, as is start production with
> > > python 2.4 (possibly even with python 2.5).
> > >

> >
> > The fact remains that you won't be able to affect the built-in classes
> > such as int and str - they are hard-coded in C (for CPython, at least),
> > and so their metaclass is also implied and cannot be changed.

>
> ...except in C.
>
> I assume the "root class" should be available/changeable in "C", too.
>
> Do I have to change the sources directly, or does python provide
> "C-level-extension/modication" mechanisms, which can be applied to
> core-level classes, too?
>
> Is the Python Object Model documented anywhere in a diagram, something
> similar to this?:
>
> http://case.lazaridis.com/wiki/RubyObjectModel


What could you possibly want to do this for so badly that you would
shun all alternatives and even resort to hacking up the runtime at the
C-level to redefine core types in non-standard and unpredictable
ways?! Seriously, please give a good reason for every doing this. I
can't imagine there is any way it would justify all this in the face
of just looking for an alternative. You aren't trying to use python,
at this point, you are trying to fork it.
 
Reply With Quote
 
Ilias Lazaridis
Guest
Posts: n/a
 
      09-19-2006
Calvin Spealman wrote:
> On 18 Sep 2006 20:23:03 -0700, Ilias Lazaridis <(E-Mail Removed)> wrote:
> > Steve Holden wrote:
> > > Ilias Lazaridis wrote:

> > ...
> > > > http://www-128.ibm.com/developerwork.../l-pymeta.html
> > > >
> > > > I am not so much interested in old-style, as is start production with
> > > > python 2.4 (possibly even with python 2.5).
> > >
> > > The fact remains that you won't be able to affect the built-in classes
> > > such as int and str - they are hard-coded in C (for CPython, at least),
> > > and so their metaclass is also implied and cannot be changed.

> >
> > ...except in C.
> >
> > I assume the "root class" should be available/changeable in "C", too.
> >
> > Do I have to change the sources directly, or does python provide
> > "C-level-extension/modication" mechanisms, which can be applied to
> > core-level classes, too?
> >
> > Is the Python Object Model documented anywhere in a diagram, something
> > similar to this?:
> >
> > http://case.lazaridis.com/wiki/RubyObjectModel

>
> What could you possibly want to do this for so badly that you would
> shun all alternatives and even resort to hacking up the runtime at the
> C-level to redefine core types in non-standard and unpredictable
> ways?! Seriously, please give a good reason for every doing this. I
> can't imagine there is any way it would justify all this in the face
> of just looking for an alternative. You aren't trying to use python,
> at this point, you are trying to fork it.


http://case.lazaridis.com/wiki/Please#OffTopicPosts

..

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
Adding a Par construct to Python? jeremy@martinfamily.freeserve.co.uk Python 66 06-05-2009 09:38 PM
Want to "tweak" the system to eke out more overall available RAM Spin Computer Support 13 09-10-2008 09:20 PM
adding a library (functionality) to an operating system aghufran C Programming 3 10-02-2006 08:20 PM
CPU Usage % spikes wildly; system slow overall (IBM T20 laptop, 512 MB RAM) Larry Mehl Computer Support 6 07-07-2006 11:13 PM



Advertisments