This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: % operator bug
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bogo666, quiver
Priority: normal Keywords:

Created on 2005-01-14 07:25 by bogo666, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py bogo666, 2005-01-14 07:25 percent_operator_bug.py
Messages (2)
msg23960 - (view) Author: ChrisF (bogo666) Date: 2005-01-14 07:25
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@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)]
msg23961 - (view) Author: George Yoshida (quiver) (Python committer) Date: 2005-01-14 11:06
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.
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41439
2005-01-14 07:25:27bogo666create