IOError: [Errno 13] Permission denied while reading csv file in python
<p>I have quite large csv file and i am using csv module to read csv file and process it 
and below code snippet which i have in my project. The file has around 9828075 records in file the code worked fine till 637922th record later which it raise below error:</p>

<pre><code>ERROR      Tue, 14 Apr 2013 09:59:29 Traceback (most recent call last):
    File "build\bdist.win32\egg\my_proj\csv_reader.py", line 316, in next
  File "E:\MyProject\DataExa\Python26\lib\csv.py", line 104, in next
    row = self.reader.next()
  File "build\bdist.win32\egg\my_proj\csv_reader.py", line 366, in capture_record_data
IOError: [Errno 13] Permission denied
</code></pre>

<p>My code looks like below...</p>

<pre><code>import csv

class MyCsvReader (object):
"""
"""

  def __init__ (self, import_source, dialect='excel'):

    """
    """
    self.import_source = import_source
    self.dialect = dialect
    self.post_init()

  def post_init(self):
    """
    Do any post init logic....
    """
    pass

  def init_reader (self):
    self.import_file = file(self.import_source, 'rU')
    #_reader = csv.reader (self.capture_record_data(self.import_file),
    #                          dialect=self.dialect)
    # create a CSV iterator that returns a dict with each next() call        
    self.reader = csv.DictReader(self.capture_record_data(self.import_file),
                                 dialect=self.dialect)
  def next (self):
    """
    Returns a dict containing data read from the CSV file.

    """
    #todo: do a magic to remove all spaces in data....
    return self.reader.next()        


  def __iter__ (self):
    "Special method to make an instance of this class into an iterator"
    return self

  def capture_record_data (self, row_iterator):
    """
    Generator for capturing the record data before passing to csv
    """
    for row in row_iterator: 
        self.raw_data = row
        yield row

  def close(self):
    if hasattr(self, 'import_file'):
        self.import_file.close()

if __name__ == '__main__':
  reader_obj =  MyCsvReader (import_source='test.csv')
  reader_obj.init_reader()
  while True:
    try:
        print reader_obj.reader.next()
    except StopIteration, e:
        break
</code></pre>

<p>Could any one help on this to figure out why does i am getting IOError: [Errno 13] Permission denied error
while processing file.</p>

<p>Thanks,
PD</p>
