How to read csv file on Anriod device
in Expyriment
Hello
I would like use a csv file.But when I use the "import csv",it doesn't work on Anriod.Is there a simple way to read a csv file on Anriod device?
Thanks!
Comments
Hi,
indeed in the current build of the Expyriment Android Runtime, the CSV module is not included.
There are two options for now:
(1) Depending on the complexity of the CSV file you want to read, just reading it manually might be the easiest way. That is, just read in each line and then split at the delimiter. Something like this:
data = [] with open("file.csv") as f: for counter,line in enumerate(f.read()): if counter == 0: # Header col_names = line.strip().split(",") else: tmp = line.strip().split(",") for c,x in enumerate(tmp): try: tmp[c] = float(x) except: pass data.append(tmp)(2) Python's CSV module is pure Python I think, so you could copy the code from Python itself and use it with your script: