Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31134

Re: __setitem__ without position

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'class,': 0.07; 'called.': 0.09; 'subject:position': 0.09; 'cc:addr:python-list': 0.10; 'lowercase': 0.16; 'naming': 0.16; 'slicing:': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'creates': 0.18; 'variable': 0.20; 'changes': 0.20; 'cc:2**0': 0.23; 'example': 0.23; 'class.': 0.23; 'kevin': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'guess': 0.27; '50,': 0.29; '>>>>': 0.29; 'index,': 0.29; 'class': 0.29; "i'm": 0.29; 'could': 0.32; 'instances': 0.33; 'list': 0.35; 'pm,': 0.35; 'there': 0.35; 'list.': 0.35; 'add': 0.36; 'but': 0.36; 'should': 0.36; 'why': 0.37; 'item': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'received:192': 0.39; 'list,': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'more': 0.63; 'gave': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'away,': 0.84; 'received:74.208.4.194': 0.84
Date Thu, 11 Oct 2012 17:32:21 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Kevin Anthony <kevin.s.anthony@gmail.com>
Subject Re: __setitem__ without position
References <CA+C4C6c7GBdxs+jZPGNrpauvZXP7caGpPb8Q466HD7mV09731Q@mail.gmail.com> <CA+C4C6eMKa6i4Vk4b7hc8SxyDyutoRKkP9VLt0g3UWs+v5ehTw@mail.gmail.com>
In-Reply-To <CA+C4C6eMKa6i4Vk4b7hc8SxyDyutoRKkP9VLt0g3UWs+v5ehTw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:MR69dyg2f7IuoJwlMEVhGEkh4kOOnsEpQmHwIVwKqnI dOIFuPgi9uwxTH+nZDu1UUy6MatpHG92hYo4LofwVFqxGjKDpm D9aar0Bh+UO/HBFijq3z2JGPbz/V3Hc5Ldgh6AXL+LmNm3yIDb ok7Z3k3UeQvY3c6IsIdszTdOuHP/8C/j3rI/j39+R+/g1gKHG0 X6DUGuwqCYeMBzEmP2FvPICbgS+ZPmkQ8kTDCIb+t6/ETb6Yla Rn7YVpC5lxarrHhk6xsEzwrr0/N0L135rit60LoPTwnGJzg+9T tc8BdQJc91pxiu/M0wUi8Z9G7TXmX6VfRmR/YPRtBZVMK2sTA= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2068.1349991167.27098.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349991167 news.xs4all.nl 6943 [2001:888:2000:d::a6]:44437
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31134

Show key headers only | View raw


On 10/11/2012 04:48 PM, Kevin Anthony wrote:
> I have a class that contains a list of items
> I can set items using __setitem__ but if i want to set the while list, i
> changes the variable from a myclass to a list.  How can i accomblish this
> Example
>>>> C = myclass()
>>>> C[0] = 57
>>>> type(C)
> myclass
>>>> C = [57,58,59,60]
This creates a list, and binds the name that used to refer to the
myclass to now refer to the list.  The myclass object will go away,
since there are no more refs to it.

>>>> type(C)
> list
>
>
Why is that a surprise?

As for how to add multiple items to the existing mylist, how about:

for index, item in enumerate([57, 50, 59, 60]) :
    C[index] = item

Alternatively, you could call one of the other methods in the class. 
But since you gave us no clues, I'm shouldn't guess what it was called. 
But if I were to make such a class, I might use slicing:
    C[:] = [57, 50, 59, 60]

BTW, your naming capitalization is backwards.  Class names should begin
with a capital,  Myclass.  Instances should begin with lowercase -
myinstance

-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: __setitem__ without position Dave Angel <d@davea.name> - 2012-10-11 17:32 -0400

csiph-web