Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37553 > unrolled thread

using split for a string : error

Started byinshu chauhan <insideshoes@gmail.com>
First post2013-01-24 11:37 +0100
Last post2013-01-24 11:37 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  using split for a string : error inshu chauhan <insideshoes@gmail.com> - 2013-01-24 11:37 +0100

#37553 — using split for a string : error

Frominshu chauhan <insideshoes@gmail.com>
Date2013-01-24 11:37 +0100
Subjectusing split for a string : error
Message-ID<mailman.953.1359023878.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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,

    else:
        #print sp[9], sp[10]
        if sp[9] == sp[10]:
            print " Same class"
        else :
            print "Different class"

f.close()

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[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.

I have a little understanding why the programme is behaving like this ?

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web