Overriding module's class

Discussion in 'Python' started by Bruno Desthuilliers, Dec 3, 2009.

  1. 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.
    Bruno Desthuilliers, Dec 3, 2009
    #1
    1. Advertising

  2. Bruno Desthuilliers

    Pavel Skvazh Guest

    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.
    Pavel Skvazh, Dec 3, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,743
    Thomas Weidenfeller
    Oct 12, 2005
  2. John Nagle
    Replies:
    21
    Views:
    892
    Fuzzyman
    Jun 19, 2010
  3. Replies:
    3
    Views:
    150
    Ch Lamprecht
    Feb 16, 2006
  4. Tim S
    Replies:
    3
    Views:
    134
    Brian McCauley
    Jun 1, 2007
  5. Ratty
    Replies:
    1
    Views:
    133
    Ratty
    May 1, 2010
Loading...

Share This Page