Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Overriding module's class

Reply
Thread Tools

Overriding module's class

 
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      12-03-2009
Pavel Skvazh a écrit :
> Is it possible to override a class in the module or the module itself
> that is imported across the project to add new methods to it?
>
> For example I've got
>
> module 'a' with class A
>
> from a import A
>
> but I don't want to add a method to that A class not just in this
> unit, but across the project, so everywhere I'll import class A - it
> would be a modified one.
>


Google for "monkey patch".

FWIW, what turns a function into a method is not the fact that it has
been defined with a class statement, but the fact that it's an attribute
of a class object. Where the function is defined is totally irrelevant.
 
Reply With Quote
 
 
 
 
Pavel Skvazh
Guest
Posts: n/a
 
      12-03-2009
Is it possible to override a class in the module or the module itself
that is imported across the project to add new methods to it?

For example I've got

module 'a' with class A

from a import A

but I don't want to add a method to that A class not just in this
unit, but across the project, so everywhere I'll import class A - it
would be a modified one.

Thank you.
 
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
Junit: overriding original class private methods Robert M. Gary Java 1 12-29-2006 01:37 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Problem overriding >> and << in a template class franklini@hotmail.com C++ 2 03-10-2005 11:33 AM
overriding method that returns base class object Stuart McGraw Python 10 02-17-2004 04:48 PM
Bug or Feature with (overriding) Class Variables? Eric Baker Python 4 11-16-2003 08:38 PM



Advertisments