Does csv.DictReader store file in memory?
<p>I have to read a large CSV file almost of 100K rows in the file, also it will be very easier to process that file if I can read each file row in a dictionary format.</p>

<p>After little research I found python's built-in function <a href="https://docs.python.org/2/library/csv.html#csv.DictReader" rel="nofollow">csv.DictReader</a> from the csv module.</p>

<p>But in the documentation it is not clear mentioned whether it stores whole file in memory or not. </p>

<p>But it has mentioned that: </p>

<blockquote>
  <p>The fieldnames parameter is a sequence whose elements are associated with the fields of the input data in order.  </p>
</blockquote>

<p>But I'm not sure whether sequence is stored in memory or not.</p>

<p>So the question is, does it store whole file in the memory?</p>

<p>If so, is there any other option to read single row as a generaror expression from the file and read get row as dict .</p>

<p>Here is my code:</p>

<pre><code>def file_to_dictionary(self, file_path):
    """Read CSV rows as a dictionary """
    file_data_obj ={}
    try:
        self.log("Reading file: [{}]".format(file_path))
        if os.path.exists(file_path): 
            file_data_obj = csv.DictReader(open(file_path, 'rU'))
        else:
            self.log("File does not exist: {}".format(file_path))
    except Exception as e:
        self.log("Failed to read file.", e, True)
    return file_data_obj
</code></pre>