[Tutor] string from input file
Mike.Hansen at atmel.com
Wed Apr 30 00:07:50 CEST 2008
> -----Original Message-----
> Behalf Of Bryan Fodness
> Sent: Tuesday, April 29, 2008 3:54 PM
> To: tutorpythonmailinglist Python
> Subject: [Tutor] string from input file
> I am trying to get values from an input file,
> but, when I check to see if they are equal it is not true.
> f = open(infile, 'r')
> s = f.readlines()
> Block = str(s)
> Angle = float(s)
> Position = str(s)
> if Block == 'Custom':
> print 'equal'
> if I print Block+'Custom', I get,
> when I would have expected
> 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.
Your string has a line ending in it, so it doesn't match. It's
essentially "Custom\n". Just use a slice to remove the line ending
character(\n). Also, I don't think you need to convert s to a
string. I think it's already a string.
Block = s[:-1]
In : x = "Custom\n"
In : y = x[:-1]
In : y
More information about the Tutor