how to use pkgutils.get_data with csv.reader in python?
<p>I have a python module that has a variety of data files, (a set of csv files representing curves) that need to be loaded at runtime.  The csv module works very well </p>

<pre><code>  # curvefile = "ntc.10k.csv"
  raw = csv.reader(open(curvefile, 'rb'), delimiter=',')
</code></pre>

<p>But if I import this module into another script, I need to find the full path to the data file.</p>

<pre><code>/project
   /shared
       curve.py
       ntc.10k.csv
       ntc.2k5.csv
   /apps
       script.py
</code></pre>

<p>I want the script.py to just refer to the curves by basic filename, not with full paths.  In the module code, I can use: </p>

<pre><code>pkgutil.get_data("curve", "ntc.10k.csv") 
</code></pre>

<p>which works very well at finding the file, but it returns the csv file already read in, whereas the csv.reader requires the file handle itself.  Is there any way to make these two modules play well together?  They're both standard libary modules, so I wasn't really expecting problems.  I know I can start splitting the pkgutil binary file data, but then I might as well not be using the csv library.</p>

<p>I know I can just use this in the module code, and forget about pkgutils, but it seems like pkgutils is really exactly what this is for.</p>

<pre><code>this_dir, this_filename = os.path.split(__file__)
DATA_PATH = os.path.join(this_dir, curvefile)
raw = csv.reader(open(DATA_PATH, "rb"))
</code></pre>
