"convert" string to bytes without changing data (encoding)
Piet van Oostrum
piet at vanoostrum.org
Wed Aug 29 19:39:15 EDT 2012
Heiko Wundram <modelnine at modelnine.org> writes:
> Reading from stdin/a file gets you bytes, and
> not a string, because Python cannot automagically guess what format the
> input is in.
>
Huh?
Python 3.3.0rc1 (v3.3.0rc1:8bb5c7bc46ba, Aug 25 2012, 10:09:29)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input()
abcd123
>>> x
'abcd123'
>>> type(x)
<class 'str'>
>>> y = sys.stdin.readline()
abcd123
>>> y
'abcd123\n'
>>> type(y)
<class 'str'>
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list