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: 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 Subject: Re: Python3.3 str() bug? Date: Fri, 09 Nov 2012 10:37:11 +0100 References: 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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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