Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; '(python': 0.07; 'binary': 0.07; 'revision': 0.07; 'to:addr:pobox.com': 0.09; 'to:addr:skip': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; '2.7': 0.14; 'expected,': 0.16; 'expecting': 0.16; 'expects': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'lang': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'subject:between': 0.16; 'typeerror:': 0.16; 'unicode?': 0.16; 'wrote:': 0.18; 'result.': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'basis,': 0.24; 'skip': 0.24; 'unicode': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; "doesn't": 0.30; '13,': 0.31; 'context,': 0.31; 'python2.7': 0.31; 'file': 0.32; 'probably': 0.32; 'stuff': 0.32; 'text': 0.33; 'older': 0.33; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:com.au': 0.36; 'skip:" 50': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'branch': 0.38; 'received:211': 0.38; 'expect': 0.39; 'system.': 0.39; 'how': 0.40; 'john': 0.61; 'content-disposition:inline': 0.62; 'default': 0.69; 'safe': 0.72; '12.1': 0.84; '2.7.': 0.84; 'ships': 0.84; 'subject:skip:S 10': 0.84; '2013,': 0.91; 'whereas': 0.91 Date: Fri, 31 May 2013 09:15:19 +1000 From: Cameron Simpson To: Skip Montanaro Subject: Re: Surprising difference between StringIO.StringIO and io.StringIO MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=e/de0tV/ c=1 sm=1 a=wom5GMh1gUkA:10 a=oVsC9x2Q-Z4A:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=hVsegU_SU28A:10 a=ybZZDoGAAAAA:8 a=feLJS7OVIkgh0oeg4sEA:9 a=CjuIK1q_8ugA:10 a=qIVjreYYsbEA:10 a=ChdAjXE5lkUvdteQbhpnkQ==:117 Cc: Python 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369955741 news.xs4all.nl 15922 [2001:888:2000:d::a6]:48195 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46553 On 30May2013 15:46, Skip Montanaro wrote: | Consider this quick session (Python 2.7 using the tip of the 2.7 | branch in Mercurial): | | % python2.7 | Python 2.7.5+ (2.7:93eb15779050, May 30 2013, 15:27:39) | [GCC 4.4.6 [TWW]] on linux2 [...] | >>> import io | >>> s2 = io.StringIO() [...] | File "/home/skipm/x86_64-linux3.1/lib/python2.7/traceback.py", line | 13, in _print | file.write(str+terminator) | TypeError: unicode argument expected, got 'str' | >>> print s2.getvalue() | | What is it about io.StringIO that it doesn't like strings and requires | Unicode? This is on an OpenSUSE 12.1 system. I have tried with LANG | set to the default ("en_US.UTF-8") and to "C". I also tried on a | Solaris system with an older micro revision of Python 2.7. Same | result. | | Am I missing something about how io.StringIO works? I thought it was | a more-or-less drop-in replacement for StringIO.StringIO. I would expect io.StringIO to be a match for the io.* stuff in Python 3. So it should care whether it is a binary stream or a text stream. Whereas StringIO.StringIO is your good old Python 2 StringIO, which expects strs. On that basis, io.StringIO is a text stream, expecting Unicode objects for transcription. 'str' is, in that context, probably considered as 'bytes' in Python 3. Cheers, -- Cameron Simpson A ship in harbor is safe - but that is not what ships are for. - John A. Shedd