Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'exception': 0.03; 'syntax': 0.03; 'subject:Error': 0.07; 'subject:file': 0.07; '"w")': 0.09; 'loop.': 0.09; 'subject:python': 0.11; 'csv': 0.16; 'subject:CSV': 0.16; 'subject:writing': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'module': 0.19; 'trying': 0.21; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; '(most': 0.27; 'am,': 0.27; '???': 0.27; 'error': 0.30; 'checked': 0.30; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'like:': 0.33; 'traceback': 0.33; 'handle': 0.33; 'to:addr:python- list': 0.33; 'doing': 0.35; 'but': 0.36; 'data.': 0.36; 'possible': 0.37; 'two': 0.37; 'why': 0.37; 'item': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'end': 0.40; 'skip:w 30': 0.61; 'programme': 0.69; 'received:74.208': 0.71; '11:': 0.84; '12:': 0.84; 'received:74.208.4.194': 0.84; 'theirs': 0.84 Date: Mon, 11 Feb 2013 09:22:19 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Error in reading and writing CSV format file in python References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:zE6mJ66YKs7EuAfpti4URZ3LiDChSguNdHOy8bHDN5b PqCtEHxzUgAcCa6qrtxEp0w7ON5AyuubjgxPMRRaRu2OSrHMAM teR4cUMRDGd+9AmTTqwU5Ghn/Nh53gIqlqZN09e6bYjjdhLYMs 9VHETG1llbQGdrsZ6z1cSZvNN3yvROIff/2drzc8US2p9B5uDP NBE43BzwH/LZBL6wV948UyARheBtL5nWDtxjIluAhrb3JtnZIV xOULydNSBsgOeutkiujF9I9sL7pLHoqBqRM9E73yqmHM9iFjFN N32pjXkWc4YlZTzoV/Qrm5tb8EsrhDLbJLVd5l0og3ElPMdEw= = 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360592556 news.xs4all.nl 6942 [2001:888:2000:d::a6]:44733 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38686 On 02/11/2013 06:00 AM, inshu chauhan wrote: > In the programme below I am trying to read two csv format files and process > them and write a new file with some of theirs data. > > import csv > f1_reader = csv.reader(open(r"Z:\Weka > work\Feature_Vectors_Fullset_00.arff")) > f2_reader = csv.reader(open(r"Z:\Weka > work\Feature_Vectors_Fullset_00_noxy+class.arff")) > nf = open(r"Z:\Weka work\classified_image00_withoutxy.arff", "w") > > while True: > l1 = f1_reader.next() > while len(l1) != 12: > l1 = f1_reader.next() > l2 = f2_reader.next() > while len(l2) != 11: > l2 = f2_reader.next() > > ix = l1[0].strip() > iy = l1[1].strip() > classification = l2[8].strip() > > print >> nf, ix, iy, classification > > nf.close() > > This programme is giving me this error now : > > Traceback (most recent call last): > File "Z:\Weka work\final_image_classificationwithoutxy.py", line 16, in > > l2 = f2_reader.next() > StopIteration > > > what could be a possible reason to StopIteration ??? > > > I checked the syntax and usage of this module looks alright to me , but > then why this error ? > > That's not an error, it's just a normal way to end a for-loop. If you were using a syntax like: for item in f2_reader: the StopIteration would simply end the loop. Since you're doing it manually, you have to handle the exception yourself. -- DaveA