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


Groups > comp.lang.python > #47579

Re: Encoding questions (continuation)

References <mailman.2964.1370862786.3114.python-list@python.org> <51b5bb53$0$29997$c3e8da3$5496439d@news.astraweb.com> <71d585e6-bb98-47b7-9a45-7cde1ba0c48f@googlegroups.com>
Date 2013-06-10 17:17 +0100
Subject Re: Encoding questions (continuation)
From Fábio Santos <fabiosantosart@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2973.1370882588.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 10 Jun 2013 15:04, "Νικόλαος Κούρας" <nikos.gr33k@gmail.com> wrote:
>
> Τη Δευτέρα, 10 Ιουνίου 2013 2:41:07 μ.μ. UTC+3, ο χρήστης Steven D'Aprano
έγραψε:
> > On Mon, 10 Jun 2013 14:13:00 +0300, Νικόλαος Κούρας wrote:
> >
> >
> >
> > > Τη Δευτέρα, 10 Ιουνίου 2013 1:42:25 μ.μ. UTC+3, ο χρήστης Andreas
> >
> > > Perstinger έγραψε:
> >
> > >
> >
> > >  >  >>> s = b'\xce\xb1'
> >
> > >  >
> >
> > >  >  >>> s[0]
> >
> > >  >
> >
> > >  > 206
> >
> > >
> >
> > > 's' is a byte object, how can you treat it as a string asking to
present
> >
> > > you its first character?
> >
> >
> >
> > That is not treating it as a string, and it does not present the first
> >
> > character. It presents the first byte, which is a number between 0 and
> >
> > 255, not a character.
> >
> >
> >
> > py> alist = [0xce, 0xb1]
> >
> > py> alist[0]
> >
> > 206
>
>
> To my mind alist[0] should yield '0xce'

This happens because 0xce is an integer object too. Integer objects have no
"memory" of what format they were declared on. Oxce just happens to be 206
in hexadecimal. Ob10 would also result in the integer 2.

> > Is that treating alist as a string? No, of course not. Strings are not
> >
> > the only object that have indexing object[position].
>
> Yes actually it does.
>
> s string is a series of characters.
>
> a list is a series of objects, which can be chars, strings, integers,
other data structures.
>
> So doing a_list[0] is similar of doing a_string[00
>
>
> > >  > A byte object is a sequence of bytes (= integer values) and support
> > > indexing
>
>
> Isn't a byte a series of zeros and ones, like 01010101 ?
> So why you say bytes are integers since its numbers into a binary system?
> perhsp you mean a represantaion of a bye to a decimal value?

A byte is a number, stored in (usually) 8 binary digits. By addressing a
bytes object by its index, you get an integer of that byte. That's just how
python deals with it.

You should heed Steven's advice and read up on basic computing. You seem to
be lacking a lot of basic concepts.

Cheers.

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


Thread

Encoding questions (continuation) Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 14:13 +0300
  Re: Encoding questions (continuation) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-10 11:41 +0000
    Re: Encoding questions (continuation) Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-10 06:56 -0700
      Re: Encoding questions (continuation) Fábio Santos <fabiosantosart@gmail.com> - 2013-06-10 17:17 +0100
      Re: Encoding questions (continuation) Larry Hudson <orgnut@yahoo.com> - 2013-06-11 00:52 -0700
        Re: Encoding questions (continuation) Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-11 13:09 -0700
          Re: Encoding questions (continuation) Larry Hudson <orgnut@yahoo.com> - 2013-06-12 01:20 -0700
            Re: Encoding questions (continuation) Larry Hudson <orgnut@yahoo.com> - 2013-06-12 01:32 -0700
      OT: e-mail reply to old/archived message (was Re: Encoding questions (continuation)) Andreas Perstinger <andipersti@gmail.com> - 2013-06-11 13:21 +0200
        Re: OT: e-mail reply to old/archived message (was Re: Encoding questions (continuation)) Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-11 13:14 -0700
          Re: OT: e-mail reply to old/archived message Andreas Perstinger <andipersti@gmail.com> - 2013-06-12 00:13 +0200
            Re: OT: e-mail reply to old/archived message nagia.retsina@gmail.com - 2013-06-11 18:16 -0700
              Re: OT: e-mail reply to old/archived message Phil Connell <pconnell@gmail.com> - 2013-06-12 07:36 +0100
                Re: OT: e-mail reply to old/archived message nagia.retsina@gmail.com - 2013-06-11 23:58 -0700
    Re: Encoding questions (continuation) Lele Gaifax <lele@metapensiero.it> - 2013-06-11 00:19 +0200
      Re: Encoding questions (continuation) Νικόλαος Κούρας <nikos.gr33k@gmail.com> - 2013-06-11 13:06 -0700

csiph-web