Bugs item #1215146, was opened at 2005-06-05 06:11 Message generated for change (Comment added) made by azgordo 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: elgordo (azgordo) Date: 2005-06-05 07:54 Message: Logged In: YES user_id=1291540 OK --- I was confused by the documentation. I'd like to propose the following replacement for the documentation: int([x[, b]]) Converts base b numbers specified by the inputs to their decimal integer equivalents. When the base b is absent x may be either (i) the string representation of a possibly signed decimal integer (possibly embedded in whitespace), or (ii) a possibly signed decimal integer or floating point number (floating point numbers are truncated towards zero). If the base b is present and non-zero, it must be an integer in the range [2, 36] and x must be the possibly signed string representation of an integer in base b notation. When x is a string and the base b is zero, the base actually used is guessed by interpreting the string x in the same way as for integer literals. When b is present then (i) if x is not a string a TypeError is raised, and (ii) if the string x does not represent an integer then a ValueError is raised. Returns 0 if no arguments are given. ---------------------------------------------------------------------- Comment By: elgordo (azgordo) Date: 2005-06-05 07:52 Message: Logged In: YES user_id=1291540 OK --- I was confused by the documentation. I'd like to propose the following replacement for the documentation: int([x[, b]]) Converts base b numbers specified by the inputs to their decimal integer equivalents. When the base b is absent x may be either (i) the string representation of a possibly signed decimal integer (possibly embedded in whitespace), or (ii) a possibly signed decimal integer or floating point number (floating point numbers are truncated towards zero). If the base b is present and non-zero, it must be an integer in the range [2, 36] and x must be the possibly signed string representation of an integer in base b notation. When x is a string and the base b is zero, the base actually used is guessed by interpreting the string x in the same way as for integer literals. When b is present then (i) if x is not a string a TypeError is raised, and (ii) if the string x does not represent an integer then a ValueError is raised. Returns 0 if no arguments are given. ---------------------------------------------------------------------- Comment By: Reinhold Birkenfeld (birkenfeld) Date: 2005-06-05 07: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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com