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


Groups > comp.lang.python > #33005

Re: Python3.3 str() bug?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:bug': 0.05; 'arg': 0.09; 'bytearray': 0.09; 'bytes,': 0.09; 'encoding.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'typeerror:': 0.09; 'bug': 0.10; 'buffer- like': 0.16; 'decode': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'general.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'str()': 0.16; 'stefan': 0.17; 'equivalent': 0.20; 'idea': 0.24; 'pass': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'object,': 0.27; 'header:X-Complaints-To:1': 0.28; 'fine': 0.28; 'probably': 0.29; "i'm": 0.29; 'normally': 0.30; 'error': 0.30; 'code': 0.31; 'asking': 0.32; 'received:84': 0.32; 'structure': 0.32; 'function.': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'clear': 0.35; 'subject:?': 0.35; 'something': 0.35; 'list.': 0.35; 'received:org': 0.36; 'but': 0.36; 'alone': 0.36; 'rather': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'subject: ': 0.66; 'funny': 0.78; 'received:arcor- ip.net': 0.84; 'received:pools.arcor-ip.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: Python3.3 str() bug?
Date Fri, 09 Nov 2012 10:37:11 +0100
References <ag402kFkb9hU1@mid.dfncis.de>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host dslb-084-056-057-031.pools.arcor-ip.net
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2
In-Reply-To <ag402kFkb9hU1@mid.dfncis.de>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3483.1352453842.27098.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352453842 news.xs4all.nl 6889 [2001:888:2000:d::a6]:43841
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33005

Show key headers only | 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