views:

4481

answers:

7

I keep getting this :

DeprecationWarning: integer argument expected, got float

How do I make this message go away? Is there a way to avoid warnings in Python?

+3  A: 

Pass the correct arguments? :P

On the more serious note, you can pass the argument -Wi::DeprecationWarning on the command line to the interpreter to ignore the deprecation warnings.

shylent
+5  A: 

Convert the argument to int. It's as simple as

int(argument)
Gonzalo Quero
+19  A: 

I Googled and found:

 #!/usr/bin/env python -W ignore::DeprecationWarning

If you're on Windows: pass -W ignore::DeprecationWarning as an argument to Python.

(But resolving the issue may be a better course of action... casting to int is not hard.)

Stephan202
casting works too .. but the flag was helpful !
Mohammed
+2  A: 

Not to beat you up about it but you are being warned that what you are doing will likely stop working when you next upgrade python. Convert to int and be done with it.

BTW. You can also write your own warnings handler. Just assign a function that does nothing. http://stackoverflow.com/questions/858916/how-to-redirect-python-warnings-to-a-custom-stream

SpliFF
+8  A: 

You should just fix your code but just in case,

import warnings
warnings.filterwarnings("ignore")
cartman
+5  A: 

I had these:

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/persisted/sob.py:12: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import os, md5, sys

/home/eddyp/virtualenv/lib/python2.6/site-packages/Twisted-8.2.0-py2.6-linux-x86_64.egg/twisted/python/filepath.py:12: DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha

Fixed it with:

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore",category=DeprecationWarning)
    import md5, sha

yourcode()

Now you still get all the other DeprecationWarnings, but not the ones caused by import md5, sha

Eddy Pronk
Really, really old, I know. But this just helped me out so much! Thanks
Bryan Ross
+4  A: 

I found the cleanest way to do this (especially on windows) is by adding the following to C:\Python26\Lib\site-packages\sitecustomize.py:

import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

Note that I had to create this file. Of course, change the path to python if yours is different.

Tristan Havelick