[Numpy-discussion] npfile deprecation warning

Brennan Williams brennan.williams@visualreservoir....
Mon Jun 15 19:25:41 CDT 2009


Robert Kern wrote:
> 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. 

My mistake. I saw the "new in 2.1" at the top of the page but didn't 
read all the way to the bottom where catch_warnings is documented (with 
"new in 2.6").
> I recommend setting up the simplefilter in your main()
> function, and only for DeprecationWarnings.
>
>   
done and it works. Thanks.
>> 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
>
>   





More information about the Numpy-discussion mailing list