Re: [Python-Dev] Slice as a copy... by design?

2008-05-23 Thread Nick Coghlan
Greg Ewing wrote: Some way of explicitly requesting a view into another string might be desirable, but it shouldn't be the default behaviour for string slicing. Backporting 3.0's memoryview to 2.6 would be the way to go about that. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] |

[Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Facundo Batista
Hi! A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. I couldn't answer why, so I'm asking here...Is it because the reference counting will be complicated? Is it because it'd be

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Oleg Broytmann
On Thu, May 22, 2008 at 12:28:47PM -0300, Facundo Batista wrote: considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. I remember some discussions... let me see... google to help... aha:

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Gary Herron
Facundo Batista wrote: Hi! A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. I couldn't answer why, so I'm asking here...Is it because the reference counting will be complicated? Is

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Scott Dial
Facundo Batista wrote: I couldn't answer why, so I'm asking here...Is it because the reference counting will be complicated? Is it because it'd be inefficient in other way? It's something else? Or is something that could be done... but is not done yet? If we changed Python to

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Facundo Batista
2008/5/22 Oleg Broytmann [EMAIL PROTECTED]: I remember some discussions... let me see... google to help... aha: http://mail.python.org/pipermail/python-3000/2006-August/003224.html http://mail.python.org/pipermail/python-3000/2006-August/003242.html These descussions are too general, and

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Facundo Batista
2008/5/22 Isaac Morland [EMAIL PROTECTED]: By contrast, the worst that can happen with no sharing is that performance and memory use is what you expect - the only bad is the apparent missed opportunity for optimization. Exactly, apparent. Also, this could be handled like a good writing tip.

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Aahz
On Thu, May 22, 2008, Facundo Batista wrote: A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. Someone did a patch for this at one point, but I don't remember what happened. --

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Christian Heimes
Facundo Batista schrieb: Hi! A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. Because the reference approach is more complicated, harder to implement and may lead to unexpected

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Guido van Rossum
On Thu, May 22, 2008 at 10:01 AM, Aahz [EMAIL PROTECTED] wrote: On Thu, May 22, 2008, Facundo Batista wrote: A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. Someone did a patch

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Isaac Morland
On Thu, 22 May 2008, Christian Heimes wrote: The buffer interface was designed for the slice-as-copy use case: a = abcdefg b = buffer(a, 2, 3) b read-only buffer for 0x839c2e0, size 3, offset 2 at 0x8391c40 str(b) 'cde' [] This answers my musing about shared slices. But it points me

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Stefan Behnel
Isaac Morland wrote: On Thu, 22 May 2008, Christian Heimes wrote: The buffer interface was designed for the slice-as-copy use case: a = abcdefg b = buffer(a, 2, 3) b read-only buffer for 0x839c2e0, size 3, offset 2 at 0x8391c40 str(b) 'cde' [] This answers my musing about shared

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Christian Heimes
Stefan Behnel schrieb: Even worse, it's gone in Py3: No, it has been replaced by a better system. Try memoryview Christian ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe:

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Stefan Behnel
Hi, Christian Heimes wrote: Stefan Behnel wrote: Even worse, it's gone in Py3: No, it has been replaced by a better system. Try memoryview I know. We are already discussing the buffer protocol on the Cython list.

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Martin v. Löwis
I couldn't answer why, so I'm asking here...Is it because the reference counting will be complicated? Is it because it'd be inefficient in other way? It's something else? Or is something that could be done... but is not done yet? There are two problems with that approach: a) you may hold

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Greg Ewing
Facundo Batista wrote: A thread in PyAr raised the question that, considering that strings are immutable, why a slice of a string is a copy and not a reference to a part of that string. Because it would make it too easy to accidentally keep a large string alive via a reference to a small part

Re: [Python-Dev] Slice as a copy... by design?

2008-05-22 Thread Facundo Batista
2008/5/22 Facundo Batista [EMAIL PROTECTED]: I couldn't answer why, so I'm asking here...Is it because the reference counting will be complicated? Is it because it'd be inefficient in other way? It's something else? Or is something that could be done... but is not done yet? Thank you all for