<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi,<br>
<br>
do a "print sp" after the split and you might see that the strings
don't look as you expected. There might be leading or trailing
whitespaces in the splitted strings and in sp[10] there probably
is a line break "\n" at the end.<br>
To remove those unwanted characters you could use the strip()
function.<br>
<br>
So your code could be:<br>
<br>
if sp[9].strip() == sp[10].strip():<br>
print "Same class"<br>
else:<br>
print "Different class"<br>
<br>
At least this works for me when I tried it...<br>
<br>
Am 24.01.2013 11:37, schrieb inshu chauhan:<br>
</div>
<blockquote
cite="mid:CAFqGZRGMXcku_nM_LqPsHpCzqGxF57LOSKwKwoCH+LyhPA8t_A@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>Here I have a code which basically reads a csv file,
tries to compare the last 2 items in each line of the
file. <br>
<br>
f = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff")<br>
for l in f:<br>
sp = l.split(",")<br>
if len(sp) != 11:<br>
print >> of, l,<br>
<br>
else:<br>
#print sp[9], sp[10]<br>
if sp[9] == sp[10]:<br>
print " Same class" <br>
else :<br>
print "Different class"<br>
<br>
f.close()<br>
<br>
</div>
For me I think the programme is logically correct, but its
giving me results which are strange. <br>
</div>
It is Printing " Different Class" even when sp[9] is equal
to sp[10] and "Same class" when sp[9] is not equal to sp[10].
and sp[9] and sp[10] are simple integers like 3, 3, 4 ,4. <br>
<br>
</div>
I have a little understanding why the programme is behaving like
this ?<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</body>
</html>