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


Groups > comp.lang.python > #77679

Re: How to turn a string into a list of integers?

Newsgroups comp.lang.python
Date 2014-09-07 11:34 -0700
References (10 earlier) <540bb91c$0$29969$c3e8da3$5496439d@news.astraweb.com> <mailman.13849.1410101559.18130.python-list@python.org> <540c8fc4$0$29973$c3e8da3$5496439d@news.astraweb.com> <8b80fe39-4aea-4a17-a1a6-a44f0b42fb7b@googlegroups.com> <540c9f19$0$29999$c3e8da3$5496439d@news.astraweb.com>
Message-ID <c6fd8f40-06aa-4332-8f96-8801b8792f49@googlegroups.com> (permalink)
Subject Re: How to turn a string into a list of integers?
From Rustom Mody <rustompmody@gmail.com>

Show all headers | View raw


On Sunday, September 7, 2014 11:38:41 PM UTC+5:30, Steven D'Aprano wrote:
> Rustom Mody wrote:

> > On Sunday, September 7, 2014 10:33:26 PM UTC+5:30, Steven D'Aprano wrote:
> >> MRAB wrote:
> >> > I don't think you should be saying that it stores the string in Latin-1
> >> > or UTF-16 because that might suggest that they are encoded. They
> >> > aren't.
> >> Of course they are encoded. Memory consists of bytes, not Unicode code
> >> points, [...]

> > Dunno about philosophical questions -- especially unicode :-)
> > What I can see (python 3) which is I guess what MRAB was pointing out:
> >>>> "".encode
> >>>> "".decode
> > Traceback (most recent call last):
> > AttributeError: 'str' object has no attribute 'decode'

> What's your point? I'm talking about the implementation of how strings are
> stored in memory, not what methods the str class provides.

The methods (un)available reflect what're the (in)valid operations on
the type:

Strings

The items of a string object are Unicode code units.  Conversion from
and to other encodings are possible through the string method
encode().

Bytes

A bytes object is an immutable array. The items are 8-bit bytes,
represented by integers in the range 0 <= x < 256. Bytes literals
(like b'abc' and the built-in function bytes() can be used to
construct bytes objects. Also, bytes objects can be decoded to
strings via the decode() method.

From https://docs.python.org/3.1/reference/datamodel.html#the-standard-type-hierarchy



IOW I interpret MRAB's statement that strings should not be thought 
of as encoded because they consist of abstract code-points, seems to me (a unicode-ignoramus!) a reasonable outlook

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


Thread

How to turn a string into a list of integers? cl@isbd.net - 2014-09-03 13:27 +0100
  Re: How to turn a string into a list of integers? Peter Otten <__peter__@web.de> - 2014-09-03 14:52 +0200
    Re: How to turn a string into a list of integers? cl@isbd.net - 2014-09-03 15:48 +0100
      Re: How to turn a string into a list of integers? Joshua Landau <joshua@landau.ws> - 2014-09-04 22:06 +0100
        Re: How to turn a string into a list of integers? cl@isbd.net - 2014-09-05 09:42 +0100
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 19:56 +0200
            Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 15:47 +1000
              Re: How to turn a string into a list of integers? Peter Otten <__peter__@web.de> - 2014-09-06 10:22 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 21:17 +1000
              Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-06 14:15 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-07 04:19 +1000
                Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-06 21:28 +0200
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-07 11:47 +1000
                Re: How to turn a string into a list of integers? MRAB <python@mrabarnett.plus.com> - 2014-09-07 15:52 +0100
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 03:02 +1000
                Re: How to turn a string into a list of integers? Rustom Mody <rustompmody@gmail.com> - 2014-09-07 10:53 -0700
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 04:08 +1000
                Re: How to turn a string into a list of integers? Rustom Mody <rustompmody@gmail.com> - 2014-09-07 11:34 -0700
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 10:14 +1000
                Re: How to turn a string into a list of integers? Marko Rauhamaa <marko@pacujo.net> - 2014-09-08 08:44 +0300
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 15:53 +1000
                Re: How to turn a string into a list of integers? Terry Reedy <tjreedy@udel.edu> - 2014-09-08 03:41 -0400
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 01:04 +1000
                Re: How to turn a string into a list of integers? Roy Smith <roy@panix.com> - 2014-09-07 11:40 -0400
                Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-08 04:00 +1000
                Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-08 10:12 +1000
              Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-06 22:23 +1000
          Re: How to turn a string into a list of integers? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-09-05 20:25 +0200
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 21:16 +0200
          Re: How to turn a string into a list of integers? Kurt Mueller <kurt.alfred.mueller@gmail.com> - 2014-09-05 22:41 +0200
      Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-05 10:12 +1000
      Re: How to turn a string into a list of integers? Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-04 20:09 -0600
      Re: How to turn a string into a list of integers? Chris Angelico <rosuav@gmail.com> - 2014-09-05 12:15 +1000
        Re: How to turn a string into a list of integers? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 14:27 +1000
  Re: How to turn a string into a list of integers? obedrios@gmail.com - 2014-09-03 07:30 -0700

csiph-web