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


Groups > comp.lang.python > #33005

Re: Python3.3 str() bug?

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Python3.3 str() bug?
Date 2012-11-09 10:37 +0100
References <ag402kFkb9hU1@mid.dfncis.de>
Newsgroups comp.lang.python
Message-ID <mailman.3483.1352453842.27098.python-list@python.org> (permalink)

Show all headers | View raw


Helmut Jarausch, 09.11.2012 10:18:
> 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() ?

Funny idea to call this a bug in Python. What your code is asking for is to
decode the object you pass in using the "latin-1" encoding. Since a list is
not something that is "encoded", let alone in latin-1, you get an error,
and actually a rather clear one.

Note that this is not specific to Python3.3 or even 3.x. It's the same
thing in Py2 when you call the equivalent unicode() function.

Stefan

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


Thread

Python3.3  str() bug? Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-11-09 09:18 +0000
  Re: Python3.3  str() bug? Stefan Behnel <stefan_ml@behnel.de> - 2012-11-09 10:37 +0100
    Re: Python3.3  str() bug? Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-11-09 11:08 +0000
      Re: Python3.3 str() bug? Chris Angelico <rosuav@gmail.com> - 2012-11-09 23:22 +1100
        Re: Python3.3 str() bug? Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-11-09 13:13 +0000
          Re: Python3.3 str() bug? Stefan Behnel <stefan_ml@behnel.de> - 2012-11-09 18:07 +0100
          Re: Python3.3 str() bug? Terry Reedy <tjreedy@udel.edu> - 2012-11-09 18:35 -0500
      RE: Python3.3 str() bug? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-09 17:47 +0000
      Re: Python3.3 str() bug? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-10 16:45 +0000
  Re: Python3.3 str() bug? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-09 10:25 -0700

csiph-web