On Thu, 03 Sep 2009 17:10:12 +, Kreso wrote:
> I would prefer that resulting object m belonged to myclist class.
> How to obtain such behaviour? Must I somehow implement __getslice__
> method myself?
Yes; you should also implement __getitem__(), as this is used for extended
slices.
--
http:
Kreso wrote:
[...]
> I would prefer that resulting object m belonged to myclist class.
I forgot to add that mylist instances in my case have some attributes (that's
why I need special container class in the first place) which should be
preserved after splicing.
In my simple understaning of pyth
On 9/3/2009 10:10 AM Kreso said...
I am subclassing list class and it basically works, but I don't
understand why after splicing these mylist objects I don't get
returned mylist objects. What I get are list objects:
I would prefer that resulting object m belonged to myclist class.
How to obtai
Hello Chris and James,
Thank you for you guys' prompt response.
Yes, that is what I wanted to do.
I, somehow, didn't think of using those list methods.
Instead, I was looking for a single method to override.
Big Thanks!
Aki-
On Jan 6, 12:43 pm, "Chris Rebert" wrote:
> If you mean you want to r
On Tue, 2009-01-06 at 12:34 -0800, akineko wrote:
> Hello everyone,
>
> I'm creating a class which is subclassed from list (Bulit-in type).
>
> It works great.
> However, I'm having a hard time finding a way to set a new value to
> the object (within the class).
> There are methods that alter a
akineko wrote:
Hello everyone,
I'm creating a class which is subclassed from list (Bulit-in type).
It works great.
However, I'm having a hard time finding a way to set a new value to
the object (within the class).
There are methods that alter a part of the object (ex. __setitem__()).
But I coul
On Tue, Jan 6, 2009 at 12:34 PM, akineko wrote:
>
> Hello everyone,
>
> I'm creating a class which is subclassed from list (Bulit-in type).
>
> It works great.
> However, I'm having a hard time finding a way to set a new value to
> the object (within the class).
> There are methods that alter a pa
On Jun 13, 1:38 pm, Mike Kent <[EMAIL PROTECTED]> wrote:
> For Python 2.5 and new-style classes, what special method is called
> for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a
> list, and seq is some sequence)?
>
> I'm trying to subclass list, and I'm having trouble determini
"Matimus" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| So, it looks like as long as you want to subclass list, you are stuck
| implementing both __*slice__ and __*item__ methods.
Unless writing in 3.0, where they have finally disappeared.
--
http://mail.python.org/mailman/li
On Jun 13, 8:43 pm, Matimus <[EMAIL PROTECTED]> wrote:
...chop...
> So, it looks like as long as you want to subclass list, you are stuck
> implementing both __*slice__ and __*item__ methods.
>
> Matt
Thanks. That was clear and concise, just what I needed.
--
http://mail.python.org/mailman/listi
On Jun 13, 11:38 am, Mike Kent <[EMAIL PROTECTED]> wrote:
> For Python 2.5 and new-style classes, what special method is called
> for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a
> list, and seq is some sequence)?
>
> I'm trying to subclass list, and I'm having trouble determin
En Fri, 13 Jun 2008 15:38:15 -0300, Mike Kent <[EMAIL PROTECTED]> escribió:
For Python 2.5 and new-style classes, what special method is called
for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a
list, and seq is some sequence)?
I'm trying to subclass list, and I'm having trou
On Apr 25, 7:03 am, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> I want to subclass list so that each value in it is calculated at call
> time. I had initially thought I could do that by defining my own
> __getitem__, but 1) apparently that's deprecated (although I can't
> find that; got a link?), a
On Apr 25, 4:03 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote:
> I want to subclass list so that each value in it is calculated at call
> time. I had initially thought I could do that by defining my own
> __getitem__, but 1) apparently that's deprecated (although I can't
> find that; got a link?), a
spike grobstein wrote:
>>You also need to post the code that raises the error, or no one else can
>
> debug it.
>
> sorry, I thought I had pasted that line in there, but I guess I missed
> it. Here's the full code (after modifying it slightly based on your
> post):
>
> #! /usr/bin/env python
>
>You also need to post the code that raises the error, or no one else can
debug it.
sorry, I thought I had pasted that line in there, but I guess I missed
it. Here's the full code (after modifying it slightly based on your
post):
#! /usr/bin/env python
def circular_list(list):
def __getitem_
spike wrote:
> I've googled like crazy and can't seem to find an answer to why this
> isn't working.
>
> I want to create a custom list class that acts as a circular list.
>
> ie: my_list = (0, 1, 2)
Perhaps you mean [0, 1, 2]
>
> how I want it to behave:
>
> my_list[0] -> 0
> my_list[1] -> 1
spike wrote:
> I've googled like crazy and can't seem to find an answer to why this
> isn't working.
>
> I want to create a custom list class that acts as a circular list.
>
> ie: my_list = (0, 1, 2)
>
> how I want it to behave:
>
> my_list[0] -> 0
> my_list[1] -> 1
> my_list[2] -> 2
> my_list[
[Uwe]
> How [do] you clear the contents of a list subclass
> without creating a new object?
Use the paranoia emoticon: "del x[:]". For example:
>>> class L(list):
... pass
...
>>> x = L()
>>> x.append("Spam")
>>> del x[:]
>>> x
[]
>>> type(x)
>>>
with-thanks-to-Gordon-McMillan-ly y'rs,
--
class newList(list):
def clear(self):
self[:] = []
is one way.
HTH
Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml
--
http://mail.python.org/mailman/listinfo/python-list
20 matches
Mail list logo