If you want to use Python’s built-in csv
module, you need to construct a file-like object to pass to the reader. Luckily, Python also predicted the idea of interpreting a string in memory as a ‘file-like’ object, so the StringIO
module already exists.
What you want is probably something like this:
from StringIO import StringIO
fileContents = event.file.getString("UTF-8")
reader = csv.DictReader(StringIO(fileContents))
for row in reader:
print row