[Python-Dev] Changing string constants to byte arrays in Py3k
Steve Holden
steve at holdenweb.com
Sat May 5 23:30:31 CEST 2007
Steven Bethard wrote:
> On 5/5/07, M.-A. Lemburg <mal at egenix.com> wrote:
>> On 2007-05-04 19:51, Guido van Rossum wrote:
>>> [-python-dev]
>>>
>>> On 5/4/07, Fred L. Drake, Jr. <fdrake at acm.org> wrote:
>>>> On Friday 04 May 2007, M.-A. Lemburg wrote:
>>>> > I also suggest making all bytes literals immutable to avoid running
>>>> > into any issues like the above.
>>>>
>>>> +1 from me.
>>> Rather than adding immutability to bytes objects (which has big
>>> implementation and type checking implications), consider using
>>> buffer(b"123") as an immutable bytes literal. You can freely
>>> concatenate and compare buffer objects with bytes objects.
>> I like Georg's idea of having an immutable bytes subclass.
>> b"abc" could then be a shortcut constructor for this subclass.
>>
>> In general, I don't think it's a good idea to have literals
>> turn into mutable objects, since literals are normally perceived
>> as being constant.
>
> Does that mean you want list literals to be immutable too?
>
> lst = ['a', 'b', 'c']
> lst.append('d') # raises an error?
>
> STeVe
I think the point is rather that changes to the list linked by lst after
the initial assignment shouldn't result in the assignemtn of a different
value to lst if the statement is executed again (as part of a function
body or in a loop, for example).
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com squidoo.com/pythonology
tagged items: del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------
More information about the Python-Dev
mailing list