Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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; 'win32': 0.03; 'binary': 0.07; 'string': 0.09; 'bytes.': 0.09; 'encode': 0.09; 'objects)': 0.09; 'python': 0.11; "'w')": 0.16; 'bytes;': 0.16; 'mode,': 0.16; 'str,': 0.16; 'typeerror:': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'later': 0.20; 'feb': 0.22; '>>>': 0.22; '(in': 0.22; 'bytes': 0.24; 'skip': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '"",': 0.31; 'chase': 0.31; 'sep': 0.31; 'file': 0.32; 'lists': 0.32; 'text': 0.33; '(most': 0.33; "can't": 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'recent': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'ian': 0.60; 'first': 0.61; "you'll": 0.62; 'more': 0.64 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=7ceYlogGBUcv6qbXNF8X0uflM2eeIMJdWL8AgNmYdhc=; b=lSoHTLQ3brHFKt7b+qzQd0RlwQoi4MFz7LUk4u6nAsFOCX/vjhOhmQc9RLgKNbYonQ S/U2vMlhxuDy4fTu8FKgHNWrhvkvRsg9ci7SJw0CCASU93QrhppNW/S3v8+67na3J4BE n1Gl6QTVU0m9lmIwRijU1BWg9AaCa6kBcZeCb3WXjDA1g0OXf8sIOpJdCHaLT2MMrl2d ygvy61O04KlObzs/lujfH45XRqrU5lOlGFWFpwCRcWKOV70cmfyjT1tSizbdR58/QjnN +aHEhMdoLP71+3Lm4VofBGw5MxusGEfqPiibiWewesZMXt26AE7Cs+F5ISFEPIYBWtLs s3Nw== X-Received: by 10.68.75.9 with SMTP id y9mr54610887pbv.61.1392249714115; Wed, 12 Feb 2014 16:01:54 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20140212161427.0a9843d5@bigbox.christie.dr> References: <6c76ef4e-8c7c-4199-b30d-c4d55c1061c8@googlegroups.com> <20140212161427.0a9843d5@bigbox.christie.dr> From: Ian Kelly Date: Wed, 12 Feb 2014 17:01:13 -0700 Subject: Re: Wait... WHAT? 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: 1392249723 news.xs4all.nl 2840 [2001:888:2000:d::a6]:39687 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66122 On Wed, Feb 12, 2014 at 3:14 PM, Tim Chase wrote: > On 2014-02-12 14:35, Ian Kelly wrote: >> You can't write lists directly to files. You can only write strings >> to files. To write and read a list, you'll need to first serialize >> it and later deserialize it. > > To be pedantic, you can only write *bytes* to files, so you need to > serialize your lists (or other objects) to strings and then encode > those to bytes; or skip the string and encode your list/object > directly to bytes. The file was opened in text mode, not binary mode. Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> f = open('test.txt', 'w') >>> f.write(b'hello world') Traceback (most recent call last): File "", line 1, in TypeError: must be str, not bytes