Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:bug': 0.05; 'arg': 0.09; 'argument,': 0.09; 'bytearray': 0.09; 'bytes,': 0.09; 'components,': 0.09; 'typeerror:': 0.09; 'bug': 0.10; "wouldn't": 0.11; 'encoding': 0.15; 'buffer-like': 0.16; 'decoding': 0.16; 'general.': 0.16; 'repr()': 0.16; 'str()': 0.16; 'wrote:': 0.17; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'object,': 0.27; 'structures': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'probably': 0.29; "i'm": 0.29; 'fri,': 0.30; 'normally': 0.30; 'received:209.85.215.46': 0.30; 'error': 0.30; 'structure': 0.32; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'nov': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'list.': 0.35; 'but': 0.36; 'useful': 0.36; 'does': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=1BlHK7PGbBKEnPAoQOeaaJ5i+VcRwmEivlRSN4sVc3E=; b=VePLNChMMqnbaPrPEmtuvyP8HoQT2pStIsN+yeRKNNEp4BlinrJaV+tWRNkom2fNS6 IuO/lPS5Z/bIf6F/LdhCXsHV6hyQf8Xt+uIzpQKNdB8Vw7AUmAGnp2Rcv5niNZx4txfD 0g6IkSzMwjNLggIyBOsNrtIKQTX1MNBoBNkFNC3KrMRKmPwj4phBZKF2NUmDUbX6Pqw+ W4QLP5I7KNnJnBlojN+LObU9i7wbQWKWSqzTjww2fCn86ehtSqpCRHHjI7z3apegz9Ah D9bPCbZcsij84uzOslmVbE8eOFyxZV+1z9EgpINjat6EwOOVhlRXZQRvMiGgZtZ057wA TiIw== MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Fri, 9 Nov 2012 10:25:43 -0700 Subject: Re: Python3.3 str() bug? To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352481975 news.xs4all.nl 6977 [2001:888:2000:d::a6]:54057 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33039 On Fri, Nov 9, 2012 at 2:18 AM, Helmut Jarausch 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.