[ python-Bugs-1215146 ] int('x',radix) puzzle

SourceForge.net noreply at sourceforge.net
Sun Jun 5 16:09:00 CEST 2005


Bugs item #1215146, was opened at 2005-06-05 15:11
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1215146&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: elgordo (azgordo)
Assigned to: Nobody/Anonymous (nobody)
Summary: int('x',radix) puzzle

Initial Comment:
I don’t understand the built-in function int(x, radix). Or 
its documentation in the Library Reference section 2.1 – 
Built-In Functions. I’m using Python 2.4.1 on Windows 
XP Pro w/SP2, And I get the following on IDLE:

>>> int(9)
9
>>> int('9')
9
>>> int('9',2)

Traceback (most recent call last):
  File "<pyshell#31>", line 1, in -toplevel-
    int('9',2)
ValueError: invalid literal for int(): 9
>>> int('9',8)

Traceback (most recent call last):
  File "<pyshell#32>", line 1, in -toplevel-
    int('9',8)
ValueError: invalid literal for int(): 9
>>> int('9',10)
9
>>> int('9',16)
9
>>> int('19',16)
25
>>>


----------------------------------------------------------------------

>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-06-05 16:08

Message:
Logged In: YES 
user_id=1188172

The function is behaving as expected. The radix argument
specifies which base the number system in the string has.
Radix 2 means binary, for example, and radix 16 hexadecimal.
>From that, it is clear that '9' is an invalid binary or
octal number.

In the future, please direct such questions to the Newsgroup
comp.lang.python.

Closing as Invalid.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1215146&group_id=5470


More information about the Python-bugs-list mailing list