Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!feeder1.cambriumusenet.nl!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'received:209.85.223': 0.03; 'f.close()': 0.07; 'skip:o 50': 0.07; '#print': 0.09; '"': 0.09; 'correct,': 0.09; 'integers': 0.09; 'skip:o 60': 0.09; 'subject:string': 0.09; 'subject:using': 0.09; 'subject:error': 0.11; 'file,': 0.15; '>>': 0.16; 'csv': 0.16; 'basically': 0.17; 'tries': 0.17; 'to:name:python- list@python.org': 0.20; 'file.': 0.20; 'message- id:@mail.gmail.com': 0.27; 'behaving': 0.29; 'skip:& 10': 0.29; 'subject: : ': 0.30; 'code': 0.31; 'print': 0.32; 'to:addr:python- list': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'compare': 0.36; 'why': 0.37; 'received:209': 0.37; 'skip:l 20': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'think': 0.40; 'skip:u 10': 0.60; 'different': 0.63; 'here': 0.65; 'results': 0.65; 'programme': 0.69; '11:': 0.84; 'is\xa0': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=mqZ96YL7UvX7Wfj8d9Xx/LCYvipGVTHZNWEjhcodCls=; b=qow2HYt0N+g3lT1d2kgpqQgpo5EON2evlCaFyW55Fpq/v3gftGjqkpEcIk4R+y1S8N ghxA++8E/oeYS7lZ6aSMwbLVhCywZpFfU7+9mzhpvtMk6yywu6eo6BDa/dcVDNrAkkjR Gplk/gj3BO9QJFxxpx1HhCSn0DU7d0hj3yQqKFkgw1vmIuAfztuso6nC6fz8Qv5PdwMY DztnwXhvmkYIVDlhju1iobeJbji8fT7LGBGgH/ITl2AgvMY9Wcp5raMbPPurxebNrQp6 iREnA7BwTdnQ90iTcJ+EYmihLAkLiFWGUEUo76jLuH864qzT3iNOXoY38B+bPs28vGsv YQdg== MIME-Version: 1.0 X-Received: by 10.50.151.195 with SMTP id us3mr912629igb.40.1359023875578; Thu, 24 Jan 2013 02:37:55 -0800 (PST) Date: Thu, 24 Jan 2013 11:37:55 +0100 Subject: using split for a string : error From: inshu chauhan To: "python-list@python.org" Content-Type: multipart/alternative; boundary=e89a8f3b9f49585bf804d40667fc X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1359023878 news.xs4all.nl 6844 [2001:888:2000:d::a6]:43066 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37553 --e89a8f3b9f49585bf804d40667fc Content-Type: text/plain; charset=ISO-8859-1 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 ? --e89a8f3b9f49585bf804d40667fc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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>f =3D open(r"Z:\modules\Feature_Vectors_300_Pclass.arff")
f= or l in f:
=A0=A0=A0 sp =3D l.split(",")
=A0=A0=A0 if len(sp) !=3D 11:=A0=A0=A0=A0=A0=A0=A0 print >> of, l,
=A0=A0=A0=A0=A0=A0=A0
= =A0=A0=A0 else:
=A0=A0=A0=A0=A0=A0=A0 #print sp[9], sp[10]
=A0=A0=A0= =A0=A0=A0=A0 if sp[9] =3D=3D sp[10]:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 p= rint " Same class"
=A0=A0=A0=A0=A0=A0=A0 else :
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print &qu= ot;Different class"
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0
f.close()
For me I think the programme is logically correct, but its givin= g me results which are strange.
It is=A0 Printing " Differen= t Class"=A0 even when sp[9] is equal to sp[10] and "Same class&qu= ot; when sp[9] is not equal to sp[10].=A0 and sp[9] and sp[10] are simple i= ntegers like 3, 3, 4 ,4.

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