[ python-Bugs-1102141 ] % operator bug

SourceForge.net noreply at sourceforge.net
Fri Jan 14 12:06:36 CET 2005


Bugs item #1102141, was opened at 2005-01-14 16:25
Message generated for change (Comment added) made by quiver
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1102141&group_id=5470

Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: ChrisF (bogo666)
Assigned to: Nobody/Anonymous (nobody)
Summary: % operator bug

Initial Comment:
The attached code snippet is contains a function with a
return value using the percent operator, but the
interpreter complains about a TypeError, which is
incorrect.

Output from script is:
chris at py:~/tmp/Python-2.4$ ./python ~/python/bug.py
10 <type 'int'>
0 <type 'int'>
0 <type 'int'>
0 <type 'int'>
Traceback (most recent call last):
  File "/home/chris/python/bug.py", line 13, in ?
    str_ip = string_ip_from_long(0x0a000000L)
  File "/home/chris/python/bug.py", line 11, in
string_ip_from_long
    return ('%d.%d.%d.%d' % octets)
TypeError: int argument required


I've been able to reproduce this problem using versions:

Python 2.2.3 (#1, Jun 16 2003, 13:21:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2

Python 2.3.4 (#1, Jun 11 2004, 12:13:19)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2

Python 2.3.4 (#2, Nov 21 2004, 23:17:26)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4

(Sparc64 box:)
Python 2.3.4 (#2, Dec  3 2004, 17:25:48)
[GCC 3.3.5 (Debian 1:3.3.5-2)] on linux2

Python version details: 2.4 (#1, Jan 14 2005, 17:20:35)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)]

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

Comment By: George Yoshida (quiver)
Date: 2005-01-14 20:06

Message:
Logged In: YES 
user_id=671362

% operator requires a tuple, but you're giving it a list.

  >>> "%d.%d"%[1,2]
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  TypeError: int argument required
  >>> "%d.%d"%(1,2)
  '1.2'


2.3.6.2 String Formatting Operations 
http://docs.python.org/lib/typesseq-strings.html

% behaves as documented and is not likely a bug.

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

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


More information about the Python-bugs-list mailing list