[Numpy-discussion] npfile deprecation warning

Robert Kern robert.kern@gmail....
Mon Jun 15 18:53:43 CDT 2009


On Mon, Jun 15, 2009 at 18:48, Brennan
Williams<brennan.williams@visualreservoir.com> wrote:
> Robert Kern wrote:
>> On Mon, Jun 15, 2009 at 17:27, Brennan
>> Williams<brennan.williams@visualreservoir.com> wrote:
>>
>>> Hi
>>>
>>> I'm using npfile which is giving me a deprecation warning. For the time
>>> being I want to continue using it but I would like to suppress
>>> the warning messages. Is it possible to trap the deprecation warning but
>>> still have the npfile go ahead?
>>>
>>
>> http://docs.python.org/library/warnings
>>
>>
> Thanks.
> OK I've put the following in my code...
>
> import warnings
>
> def fxn():
>    warnings.warn("deprecated", DeprecationWarning)
>
> with warnings.catch_warnings():
>    warnings.simplefilter("ignore")
>    fxn()

catch_warnings() was added in Python 2.6, as stated in the
documentation. I recommend setting up the simplefilter in your main()
function, and only for DeprecationWarnings.

> but I'm getting an invalid syntax error...
>
> with warnings.catch_warnings():
>                       ^
> SyntaxError: invalid syntax
>
> I haven't used "with" before. Is this supposed to go in the function def
> where I use npfile? I've put it near the top of my .py file after my
> imports and before my class definitions.

You would use the with statement only around code that calls the function.

> btw I'm using Python 2.5.4

In Python 2.5, you need this at the top of your file (after docstrings
but before any other code):

from __future__ import with_statement

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the Numpy-discussion mailing list