Re: Python3.3 str() bug?

Discussion in 'Python' started by Ian Kelly, Nov 9, 2012.

  1. Ian Kelly

    Ian Kelly Guest

    On Fri, Nov 9, 2012 at 2:18 AM, Helmut Jarausch
    <-aachen.de> wrote:
    > Hi,
    >
    > probably I'm missing something.
    >
    > Using str(Arg) works just fine if Arg is a list.
    > But
    > str([],encoding='latin-1')
    >
    > gives the error
    > TypeError: coercing to str: need bytes, bytearray or buffer-like object,
    > list found
    >
    > If this isn't a bug how can I use str(Arg,encoding='latin-1') in general.
    > Do I need to flatten any data structure which is normally excepted by str() ?


    In general, the __str__ implementations of complex data structures
    will call repr() on their components, not str(). repr() normally does
    not do any decoding in the first place and does not take an encoding
    argument, so even if str([]) accepted an encoding, it wouldn't be
    useful for anything.
    Ian Kelly, Nov 9, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    2
    Views:
    470
    Thomas G. Marshall
    Aug 3, 2003
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    616
    CBFalconer
    Apr 10, 2004
  3. Sullivan WxPyQtKinter

    It is fun.the result of str.lower(str())

    Sullivan WxPyQtKinter, Mar 7, 2006, in forum: Python
    Replies:
    5
    Views:
    329
    Tim Roberts
    Mar 9, 2006
  4. Ethan Furman
    Replies:
    4
    Views:
    241
    Roy Smith
    May 27, 2011
  5. Stefan Behnel

    Re: Python3.3 str() bug?

    Stefan Behnel, Nov 9, 2012, in forum: Python
    Replies:
    5
    Views:
    278
    Oscar Benjamin
    Nov 10, 2012
Loading...

Share This Page