Re: using split for a string : error
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 there probably is a line break "\n"
at the end.
To remove those unwanted characters you could use the strip() function.
So your code could be:
if sp.strip() == sp.strip():
print "Same class"
print "Different class"
At least this works for me when I tried it...
Am 24.01.2013 11:37, schrieb inshu chauhan:
> Here I have a code which basically reads a csv file, tries to compare
> the last 2 items in each line of the file.
> f = open(r"Z:\modules\Feature_Vectors_300_Pclass.arff" )
> for l in f:
> sp = l.split(",")
> if len(sp) != 11:
> print >> of, l,
> #print sp, sp
> if sp == sp:
> print " Same class"
> else :
> print "Different class"
> For me I think the programme is logically correct, but its giving me
> results which are strange.
> It is Printing " Different Class" even when sp is equal to sp
> and "Same class" when sp is not equal to sp. and sp and
> sp are simple integers like 3, 3, 4 ,4.
> I have a little understanding why the programme is behaving like this ?
|All times are GMT. The time now is 08:55 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.