Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15614] print statement not showing valid result

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Aug 10, 2012, 1:20 AM

Post #1 of 2 (37 views)
Permalink
[issue15614] print statement not showing valid result

New submission from laki:

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
>>> a = [1,2]
>>> b = [2,3]
>>> a.extend(b)
>>> a
[1, 2, 2, 3]
>>> print [1,2].extend([2,3])
None

I did not test this in linux.

----------
components: Windows
messages: 167859
nosy: laki
priority: normal
severity: normal
status: open
title: print statement not showing valid result
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15614>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Aug 10, 2012, 1:58 AM

Post #2 of 2 (37 views)
Permalink
[issue15614] print statement not showing valid result [In reply to]

Martin v. Löwis added the comment:

This is not a bug. extend is a procedure with a side effect: the "self" object (i.e. "a" in your example) is modified.

By convention, procedures return None in Python, as opposed to functions, which have no side effect but return a result. This is to avoid code like

def combine(a, b):
return a.extend(b)

a = ...
b = ...
c = combine(a,b)

If extend would return the "self" list, then people may think that they get a fresh, new list, and then wonder why a is modified.

IOW: your bug report is actually invalid; the result that print shows is exactly the right result that extend returns.

----------
nosy: +loewis
resolution: -> invalid
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15614>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.