Re: Reading csv file

2013-12-20 Thread Igor Korot
Thank you, Peter. About OOP: company policy, can't help it. They say it's easier to maintain and code. But it works now. On Thu, Dec 19, 2013 at 2:39 AM, Peter Otten <__pete...@web.de> wrote: > Igor Korot wrote: > >> Hi, Peter, >> Thank you for the great suggestion. >> >> I tried to implement yo

Re: Reading csv file

2013-12-19 Thread Scott Jewloszewicz-Clarke
You didn't pass in self as the first arg to open. This is necessary. S On 19 December 2013 09:22, Igor Korot wrote: > Hi, Peter, > Thank you for the great suggestion. > > I tried to implement you code but failed. > > Here's what I have: > > class FileReader: > def __init__(self, filena

Re: Reading csv file

2013-12-19 Thread Peter Otten
Igor Korot wrote: > Hi, Peter, > Thank you for the great suggestion. > > I tried to implement you code but failed. > > Here's what I have: > > class FileReader: > def __init__(self, filename, isSkip): > self.path = filename > self.isSkip = isSkip > >

Re: Reading csv file

2013-12-19 Thread Igor Korot
Hi, Peter, Thank you for the great suggestion. I tried to implement you code but failed. Here's what I have: class FileReader: def __init__(self, filename, isSkip): self.path = filename self.isSkip = isSkip @contextmanager def open(*args):

Re: Reading csv file

2013-12-17 Thread Peter Otten
Igor Korot wrote: > Hi, guys, > > On Tue, Dec 17, 2013 at 12:55 AM, Peter Otten <__pete...@web.de> wrote: >> Peter Otten wrote: >> >>> You are still reading the complete csv file. Assuming >>> >>> (1) the first row of the csv contains the column names >>> (2) you want to skip the first five rows

Re: Reading csv file

2013-12-17 Thread Igor Korot
Hi, guys, On Tue, Dec 17, 2013 at 12:55 AM, Peter Otten <__pete...@web.de> wrote: > Peter Otten wrote: > >> You are still reading the complete csv file. Assuming >> >> (1) the first row of the csv contains the column names >> (2) you want to skip the first five rows of data Looking at the Peter's

Re: Reading csv file

2013-12-17 Thread Peter Otten
Peter Otten wrote: > You are still reading the complete csv file. Assuming > > (1) the first row of the csv contains the column names > (2) you want to skip the first five rows of data > > you'd have to write > > reader = csv.Reader(file) Sorry, I meant DictReader, not Reader. > line = 0 > wh

Re: Reading csv file

2013-12-17 Thread Bernd Nawothnig
On 2013-12-17, Igor Korot wrote: > Hi, ALL, > Is there a better way to do that: > > def Read_CSV_File(filename): > file = open(filename, "r") > reader = csv.DictReader(file) > line = 1 > for row in reader: > if line < 6: > reader.next() >

Re: Reading csv file

2013-12-17 Thread Peter Otten
Igor Korot wrote: > Hi, ALL, > Is there a better way to do that: > > def Read_CSV_File(filename): > file = open(filename, "r") > reader = csv.DictReader(file) > line = 1 > for row in reader: > if line < 6: > reader.next() > line++ > # pr

Re: Reading csv file

2013-12-16 Thread Mark Lawrence
On 17/12/2013 05:20, Igor Korot wrote: Hi, ALL, Is there a better way to do that: def Read_CSV_File(filename): file = open(filename, "r") reader = csv.DictReader(file) line = 1 for row in reader: if line < 6: reader.next() line++

Re: Reading csv file

2013-12-16 Thread Krishnan Shankar
Hi Igor You can use the following way to do this using "with" operator. def Read_CSV_File(filename): with open(filename, "r") as csvfile: csvreader = csv.DictReader(csvfile) line = 1 for row in csvreader: if line < 6: reader.next(

Reading csv file

2013-12-16 Thread Igor Korot
Hi, ALL, Is there a better way to do that: def Read_CSV_File(filename): file = open(filename, "r") reader = csv.DictReader(file) line = 1 for row in reader: if line < 6: reader.next() line++ # process the CSV Thank you. -- https://mail.

Re: Problem with reading CSV file from URL, last record truncated.

2009-08-03 Thread MRAB
KB wrote: On Aug 3, 3:54 pm, KB wrote: Hi, I am trying to download from a URL, a CSV using the following: import re import urllib, urllib2, cookielib import mechanize import csv import numpy import os def return_ranking(): cj = mechanize.MSIECookieJar(delayload=True) cj.load

Re: Problem with reading CSV file from URL, last record truncated.

2009-08-03 Thread KB
On Aug 3, 3:54 pm, KB wrote: > Hi, > > I am trying to download from a URL, a CSV using the following: > > import re > import urllib, urllib2, cookielib > import mechanize > import csv > import numpy > import os > > def return_ranking(): > >         cj = mechanize.MSIECookieJar(delayload=True) >  

Problem with reading CSV file from URL, last record truncated.

2009-08-03 Thread KB
Hi, I am trying to download from a URL, a CSV using the following: import re import urllib, urllib2, cookielib import mechanize import csv import numpy import os def return_ranking(): cj = mechanize.MSIECookieJar(delayload=True) cj.load_from_registry() # finds cookie index fil