so I'm writing some code which needs to pull configuration / data from CSV files, which are packaged with the application. From what I understand using pkgutil
is the 'right' way to do this. So what I'm trying to do is:
import pkgutil
MatFile = pkgutil.get_data('impy.implosions', 'LILAC_Materials.csv')
which works fine and gives me the file's bytes. But I can't figure out how to feed this into csv.reader
in a clean way. I found this old question but its solution would be something like:
MatFile = io.StringIO(MatFile)
dataReader = csv.reader(MatFile , delimiter=',')
which doesn't work since StringIO
expects a str. The complementary functionality in io
would be BytesIO
, but then that doesn't help me since csv.reader
can't handle it. It seems like this should have a simple solution, but I'm not familiar with handling byte data in python. Thanks!