vendredi 29 mai 2015

Override a package method

If I import a package, let's say networkx.

How to override one method inside it so that it's the one called by every other function inside the package ?

Example :

import networkx

def _draw_networkx_nodes(G, pos,
                        nodelist=None,
                        node_size=300,
                        node_color='r',
                        node_shape='o',
                        alpha=1.0,
                        cmap=None,
                        vmin=None,
                        vmax=None,
                        ax=None,
                        linewidths=None,
                        label=None,
                        **kwds):
     print 'OK'

nx.draw_networkx_nodes = _draw_networkx_nodes

nx.draw(G, pos)

I want the method draw to call other methods that will call my overriden function

Aucun commentaire:

Enregistrer un commentaire