471,306 Members | 837 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

__init__ method for containers

List and deque disagree on what __init__ does. Which one is
right?

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>from collections import deque
x = deque([0, 1])
x.__init__([2, 3])
x
deque([0, 1, 2, 3])
>>y = list([0, 1])
y.__init__([2, 3])
y
[2, 3]

test_deque.py even contains a test verifying its __init__
behavior, so perhaps deque has a good reason to differ from the
behavior of list.

Moreover, both methods use the same doc string, i.e.:

__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

When implementing a list-like container extension type, is there
any reason to choose anything other than list-like behavior,
i.e., if you call __init__, you'll initialize the container?
deque's behavior doesn't make sense to me.

--
Neil Cerutti
One of the causes of the American Revolution was the English put tacks in
their tea. --History Exam Blooper
Dec 12 '07 #1
2 1012
On Dec 12, 7:22 am, Neil Cerutti <horp...@yahoo.comwrote:
List and deque disagree on what __init__ does. Which one is
right?
File a bug report and assign to me.
Raymond
Dec 12 '07 #2
On 2007-12-12, Raymond Hettinger <py****@rcn.comwrote:
On Dec 12, 7:22 am, Neil Cerutti <horp...@yahoo.comwrote:
>List and deque disagree on what __init__ does. Which one is
right?

File a bug report and assign to me.
Will do. Registration in progress.

--
Neil Cerutti
Dec 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Martin Maney | last post: by
6 posts views Thread by Steven Bethard | last post: by
9 posts views Thread by Felix Wiemann | last post: by
6 posts views Thread by Rob Cowie | last post: by
8 posts views Thread by kelin,zzf818 | last post: by
4 posts views Thread by Steven D'Aprano | last post: by
25 posts views Thread by Erik Lind | last post: by
1 post views Thread by Ryan Krauss | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.