Opening a csv file for reading
Just loaded pythonista on my ipad pro.
I want to read in a data csv file which I cannot do.
Can anyone tell me where to put my data file and how do I specify the path name. I know the python command but can't get the code to recognise the file. This seems so basic, but its sending me crazy. Please help.
If you place your script and csv file in the same folder, you can usually just use local path names.
A good way to debug this type of thing:
In the console:
The "My iPad" folder is
If you are trying to open a file in iCloud or external shared file, those work differently...
Thanks for the reply.
When I type print(os.listdir)) in the console It says 'os' is not defined. Apologies for my naivety but I'm on a learning curve fairly near the origin.
I think I've got the csv and script files in the same place but how can I check. When I'm in Phythonista and I look in script library, This iPad all I see is an examples folder and my scripts. Any help appreciated
In addition I've tried print(editor.get_path())
and used the long path string that returns in my Open statement, but file still not recognised
Sorry I should have mentioned you need to
If you want to see what path your script is operating in, use
But when you got the play button pythonista sets the current path to the script path, so generally you can use open('filename') as long as filename is in the same folder as your main script.
Btw, python is case sensitive -- so make sure you check case exactly.
My file wasn’t in my scripts folder as I had thought after running your print(os.getcwd()) script. Have now managed to move the file, not obvious on the iPad, and all now works. I have been struggling with this problem for days. Thank you so much for your help.
fsdesfgee last edited by
This post is deleted!