On Tue, Apr 29, 2008 at 11:54 PM, Bryan Fodness <[EMAIL PROTECTED]> wrote:
> I am trying to get values from an input file,
>
>      0.192
>      Custom
>      15
>      IN
>
> but, when I check to see if they are equal it is not true.
>
>      f = open(infile, 'r')
>      s = f.readlines()
>      f.close()
>
>      Block = str(s[1])
>      Angle = float(s[2])
>      Position = str(s[3])
>
>      if Block == 'Custom':
>            print 'equal'
>
> if I print Block+'Custom', I get,
>
>      Custom
>      Custom
>
> when I would have expected
>
>      CustomCustom
>
> Can someone help me figure out if  I am not reading the values in correctly,
> is there a control character at the end?  The float value is ok.

There is a newline character \n at the end of each value. Below is an
explanation from an interactive python session.

>>> x = 'Custom\n'
>>> y = x.strip()
>>> y
'Custom'
>>> x
'Custom\n'
>>> print x
Custom

>>> print y
Custom
>>> print x + 'Custom'
Custom
Custom
>>> print y + 'Custom'
CustomCustom
>>>


.strip() wil strip out these newline characters so to get what you
want you should use:

Block = str(s[1].strip())

Greets
Sander
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to