Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.05; 'subject:data': 0.07; 'subject:string': 0.09; 'python': 0.11; 'bytes,': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'stdin': 0.16; 'stream.': 0.16; 'subject:changing': 0.16; 'string': 0.18; 'string,': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User- Agent:1': 0.23; 'input': 0.24; 'python3': 0.29; 'file': 0.29; 'gets': 0.32; 'guess': 0.32; 'subject: (': 0.33; 'byte': 0.33; 'in.': 0.33; 'mode': 0.33; 'skip:s 20': 0.34; 'reading': 0.34; 'subject:)': 0.36; 'header:X-Complaints-To:1': 0.36; 'text': 0.36; 'too.': 0.37; 'received:org': 0.38; 'to:addr:python-list': 0.39; 'to:addr:python.org': 0.40; 'opened': 0.66; 'skip:\xd0 20': 0.72 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: "convert" string to bytes without changing data (encoding) Date: Fri, 30 Mar 2012 22:06:45 +0300 References: "\"<9tg21lFmo3U1@mid.dfncis.de>" " <9tg4qoFbfpU1@mid.dfncis.de> <9th0u8Fuf2U1@mid.dfncis.de> <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 88.154.172.233 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20120310 Thunderbird/11.0 In-Reply-To: <1053a4e195cf2e85778f6c2c63dc89d4@modelnine.org> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 9 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333134438 news.xs4all.nl 6865 [2001:888:2000:d::a6]:60271 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22390 28.03.12 21:13, Heiko Wundram написав(ла): > Reading from stdin/a file gets you bytes, and > not a string, because Python cannot automagically guess what format the > input is in. In Python3 reading from stdin gets you string. Use sys.stdin.buffer.raw for access to byte stream. And reading from file opened in text mode gets you string too.