Thanks for your help.  This code  works :)

with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        fxn()
        shpath = g.get_shortest_paths (1,4)

where: fxn is defined by:
def fxn():
    warnings.warn ("g.get_shortest_paths",RuntimeWarning)

By the way do you have palns to implement tkplot in python?

Best

On Wed Jan 07 2015 at 4:42:43 PM Tamas Nepusz <[email protected]> wrote:

> > I set up a simple test program nettest to try to see how it is done.
> You have to put the call from which you wish to silence the warning
> *within*
> the warnings.catch_warnings() block; in your case, since the warning is
> coming
> from the get_shortest_paths() call, you have to do something like this:
>
> with warnings.catch_warnings():
>     shpath = g.get_shortest_paths(1, 4)
>
> However, warnings.catch_warnings() is quite a misnomer -- it does not
> catch any
> warnings by default. What it does is that it stores the current state of
> the
> Python warning filter when you enter the corresponding block and restores
> the
> state when you exit the block (either directly or via an exception). So, by
> default, the code I wrote above will do nothing since you don't tell
> Python to
> ignore the warnings in the following call explicitly. The full solution is
> something like this:
>
> with warnings.catch_warnings():
>     warnings.simplefilter("ignore")
>     shpath = g.get_shortest_paths(1, 4)
>
> The warnings.simplefilter() call instructs Python to update the state of
> the
> warning filter such that all warnings are ignored from now on -- therefore
> you
> won't get any warnings from get_shortest_paths(). The state of the warning
> filter is then restored when you leave the "with" block.
>
> All the best,
> T.
>
> _______________________________________________
> igraph-help mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to