[Tutor] Functions and lists.

Magnus Lycka magnus@thinkware.se
Wed, 14 Aug 2002 22:28:19 +0200


At 14:34 2002-08-14 +0200, lumbricus@gmx.net wrote:
> > >value =3D string.strip(sys.stdin.readline())
>
>This is usually done with
>value=3Dstring.strip(raw_input("prompt> "))
>IMHO

Yep, for interactive programs it usually is.
They don't behave _exactly_ the same though.

If you redirect or pipe a file to the python
program, raw_input will give an EOFError if
there is no data available, but sys.stdin.readline
will silently return an empty string.

One could say that print, input and raw_input are
higher level interfaces to sys.stdout and sys.stdin.
I usually use them. There are compact and IMO more
easy to read and write.

If you manipulate stdin or stdout, I'd suggest that
you use their read- and write-functions rather than
input/raw_input and print though.

To me it's much clearer in

sys.stdin.seek(0)
x =3D sys.stdin.readline()

than in

sys.stdin.seek(0)
x =3D raw_input()

that the second line is affected by the first.

[Books covering 1.5.2.]
>Thats not so unfortunately, because many people still
>get 1.5.x with the distribution. It would kill
>their python ambitions when none of the example codes worked.

With the distribution? By that you mean Red Hat I
gather. I do think that Red Hat ought to update the
version of Python that they ship by default. In case
someone failed to notice, a large part of the Red Hat
Linux system relies on /usr/bin/python being the old
1.5.2 version. Their more recent Python RPM install the
interpreter as /usr/bin/python2. This is a big hazzle,
since a lot of code these days require Python 2.0 or
even newer versions, and often the programs expect the
interpreter to be called python, not python2! I guess
this upgrade won't happen until the next major release.
When is RH 8.0 expected???

Anyway, I think there are many more people learning
Python 2.2 with books covering Python 1.5.2 than
vice versa...

Oh well, I still run MS Visual Studio 6, and Windows 98
on my laptop, so maybe Python 1.5.2 isn't so ancient
after all... Only three years old... 2.0 is slightly
less than 2 years. But a lot of nice new features have
appeared in Python in the last years...


--=20
Magnus Lyck=E5, Thinkware AB
=C4lvans v=E4g 99, SE-907 50 UME=C5
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se