[Python-Dev] sequence slice that wraps, bug or intention?

2009-04-03 Thread Ulrich Eckhardt
Hi!

I just stumbled across something in Python 2.6 where I'm not sure if it is by 
design or a fault:

x = 'abdc'
x[-3:-3] - ''
x[-3:-2] - 'b'
x[-3:-1] - 'bc'
x[-3: 0] - ''

The one that actually bothers me here is the last one, I would have expected 
it to yield 'bcd' instead, because otherwise I don't see a way to specify a 
slice that starts with a negative index but still includes the last element.

Similarly, I would expect x[-1,1] to yield 'ca' or at least raise an error, 
but not to return an empty string.

Bug?

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

**
Sator Laser GmbH, Fangdieckstraße 75a, 22547 Hamburg, Deutschland
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
**
   Visit our website at http://www.satorlaser.de/
**
Diese E-Mail einschließlich sämtlicher Anhänge ist nur für den Adressaten 
bestimmt und kann vertrauliche Informationen enthalten. Bitte benachrichtigen 
Sie den Absender umgehend, falls Sie nicht der beabsichtigte Empfänger sein 
sollten. Die E-Mail ist in diesem Fall zu löschen und darf weder gelesen, 
weitergeleitet, veröffentlicht oder anderweitig benutzt werden.
E-Mails können durch Dritte gelesen werden und Viren sowie nichtautorisierte 
Änderungen enthalten. Sator Laser GmbH ist für diese Folgen nicht 
verantwortlich.
**

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] sequence slice that wraps, bug or intention?

2009-04-03 Thread Paul Moore
2009/4/3 Ulrich Eckhardt eckha...@satorlaser.com:
 Hi!

 I just stumbled across something in Python 2.6 where I'm not sure if it is by
 design or a fault:

 x = 'abdc'
 x[-3:-3] - ''
 x[-3:-2] - 'b'
 x[-3:-1] - 'bc'
 x[-3: 0] - ''

 The one that actually bothers me here is the last one, I would have expected
 it to yield 'bcd' instead, because otherwise I don't see a way to specify a
 slice that starts with a negative index but still includes the last element.

 Similarly, I would expect x[-1,1] to yield 'ca' or at least raise an error,
 but not to return an empty string.

 Bug?

Feature. Documented behaviour, even
(http://docs.python.org/reference/expressions.html#id5 section
Slicings).

This question is more appropriate for python-list (comp.lang.python)
as it is about using Python, rather than the development of the Python
interpreter itself (although I can see that your uncertainty as to
whether this was a bug might have led you to think this was a more
appropriate list). You should first confirm on python-list that a
given behaviour is a bug, and if it is, post it to the tracker, rather
than to python-dev.

In this case, the behaviour is fine. As regards your point I don't
see a way to specify a slice that starts with a negative index but
still includes the last element what you want is x[-3:].

If you want to discuss this further, please do so on python-list.

Paul.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com