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: Appending non-empty element to a non-empty list yields None
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: josiahcarlson, peerjanssen
Priority: high Keywords:

Created on 2004-10-22 08:18 by peerjanssen, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg22815 - (view) Author: Peer Janssen (peerjanssen) Date: 2004-10-22 08:18
Appending a non-empty element to a non-empty list from
a dictionary results in a list of None


Scope:
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200
32 bit (Intel)] on win32 and 
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200
32 bit (Intel)] on win32
yield identical results.

Description:

The code (which is supposed to be used in a function
for deleting duplicate files...) contains this line:

print
"Warning!",(md5,len),'*',MainDic[(md5,len)],'*',name,'*',MainDic[(md5,len)].append(name)

which prints the following result:

Warning! ('5e011eda91336d21d3bfc5d5a686bb44\n', '7217')
*
['D:\\_Arbeit\\_In\\_Roaming\\_Telework\\www.ivc.ca\\part9.html',
'D:\\_Arbeit\\_I
n\\_Roaming\\_Telework\\www.ivc.ca\\part9.html.primary']
*
D:\_Arbeit\_In\_Roaming\_Telework\www.ivc.ca\part9.html.primary
* None

How can this be?

The tuple is not empty, the entry for it in the
dictionary exists, it is a list of strings, name is not
empty and a string, but appending name to the list from
the dictionary yields "None". Am I missing something,
or is this really a bug?
msg22816 - (view) Author: Peer Janssen (peerjanssen) Date: 2004-10-22 08:58
Logged In: YES 
user_id=896722

Ok, I missed something:

>>> x=['a']
>>> print x.append('b')
None
>>> print x
['a', 'b']

So this is not a bug.
msg22817 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2004-10-30 15:55
Logged In: YES 
user_id=341410

I'll also mention that you are shadowing the global 'len'
and likely global 'md5' with your variable names.

Since you seem to be relatively new to Python, I'll just say
that such things are generally frowned upon in production
Python software, as it tends to confuse others who would
read your code.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41060
2004-10-22 08:18:25peerjanssencreate