[Tutor] File IO Help again

Adam adam.jtm30 at gmail.com
Thu Oct 27 22:42:31 CEST 2005


>if line[:1] == "1":

This line won't work because you're getting the first 2 characters from the
line and seeing if it's equal to a string of length one. For example in your
test file if you put this line,
1 12.4 12.0 * 10 ,
through that bit of code it would see if "1 " == "1", which it isn't. As
Danny suggested a split should make it easier.
eg:
>>> s = "1 12.4 12.0 * 10"
>>> s.split()
['1', '12.4', '12.0', '*', '10']
>>>
then you could use
if s[0] == "1":
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051027/b8ea44e9/attachment.html


More information about the Tutor mailing list