473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Understanding (and getting rid) of optparse.py:668: FutureWarning:%u/%o/%x/%X of negative int will return a

Hi,

I get following warning with a python script:
optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will
return a signed string in Python 2.4 and up
my code:
from optparse import OptionParser

if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-G','--green',action= 'store_const', const=
'#00FF00' , dest='color',
default='#808080',
help='life is so green')
parser.add_option('-R','--red',action= 'store_const', const =
'#FF0000' , dest='color',
help='I just see red')
# add more elaborated command line parsing and help text here
(options,argv) = parser.parse_args()
print 'options',options

I assume python wants to tell me that newer version will behave
differently for numeric arguments

What I wonder is: Why do I get the warning if my code doesn't try to
parse any numbers?

Is there any way to get rid of the warning without having to change
the python version?
(I noticed, the warning disappears if I remove the line printing
options)

thanks for any explanations. suggestions
H
Sep 26 '08 #1
2 1229
hofer wrote:
Hi,

I get following warning with a python script:
optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will
return a signed string in Python 2.4 and up
my code:
from optparse import OptionParser

if __name__ == '__main__':
parser = OptionParser()
parser.add_option('-G','--green',action= 'store_const', const=
'#00FF00' , dest='color',
default='#808080',
help='life is so green')
parser.add_option('-R','--red',action= 'store_const', const =
'#FF0000' , dest='color',
help='I just see red')
# add more elaborated command line parsing and help text here
(options,argv) = parser.parse_args()
print 'options',options

I assume python wants to tell me that newer version will behave
differently for numeric arguments

What I wonder is: Why do I get the warning if my code doesn't try to
parse any numbers?
The culprit is

print options

If you look into optparse.py you'll see that part of the __repr__() method
of the Value class is the object's address, roughly

"%x" % id(self)

id(self) is just the Value instance's address in memory which seems to be
>= 0x80000000 (assuming you are on a 32-bit machine) in your case.
Such numbers were interpreted as negative ints but are now treated as
positive longs. Read

http://www.python.org/dev/peps/pep-0237/

for details.
Is there any way to get rid of the warning without having to change
the python version?
(I noticed, the warning disappears if I remove the line printing
options)
You can print options.__dict__ instead of options with little loss of
information, or turn the warning off

python -Wignore::FutureWarning myscript.py

Peter
Sep 26 '08 #2
On Sep 26, 6:21*pm, Peter Otten <__pete...@web.dewrote:
hofer wrote:
Hi,
I get following warning with a python script:
optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will
return a signed string in Python 2.4 and up

You can print options.__dict__ instead of options with little loss of
information, or turn the warning off

python -Wignore::FutureWarning myscript.py

Peter
Thanks a lot Peter,

Any trick to disable warnings just for a given range of code?
bye H

Sep 26 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: w i l l | last post by:
Why does this work the way it does? If someone could explain return true, and return false to me I'd greatly appreciate it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...
3
by: Federico Caselli | last post by:
I'm using visual basic.net, I need to take in input a string containing an expression and return the value, example: "14=14" must return true "14+14" must return 28 "8<4" must return false
2
by: PC Datasheet | last post by:
In a form/subform I have an unbound combobox in the form header that sets the value of a field in the subform so that it does not have to be entered for each record. In the BeforeUpdate event of...
2
by: fwee | last post by:
What is the difference between using exit(n) and return n in main(), if any? I know that exit(n) is a function that exits and return n exits via a return value, but is there any reason to specify...
5
by: tony collier | last post by:
To break out of a loop i have seen some people use RETURN instead of BREAK I have only seen RETURN used in functions. Does anyone know why RETURN is used instead of BREAK to kill loops?
2
by: Richard A. Wells | last post by:
All I wanted to do was implement a web service where I'd receive an XML document and return one in response. I'd already figured out how to use XmlReader and XmlWriter classes to do the XML work I...
0
by: thorley | last post by:
Greetings, I'm now merrily on my way developing a FastCGI Server in python. Thanks to help of others on this list I've got a proof of concept up and running. Herein lies my question: My goal...
2
by: joyce | last post by:
hi group, When I was trying to do a match on Regex.isMatch("$test",@"^\$") this seems to return "this expression causes side effects and will not be be evaluated", any ideas what I'm doing...
1
by: Daniel Jung | last post by:
Hi Please take a look at http://lingo.uib.no/daniel/testcase5/ where I made a (surprising) testcase (and a screenshot), involving padding-left and negative text-indent on option elements (right...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.