Sage cell server file input

30 views
Skip to first unread message

david.guichard

unread,
Oct 22, 2019, 11:52:44 AM10/22/19
to sage-support
I have a cocalc sage worksheet that reads data from a csv file. Is there any way to do this in the single cell server, that is, read data from an external file? I'm guessing not, but it would be handy.

Thanks,
David

Nils Bruin

unread,
Oct 22, 2019, 3:16:04 PM10/22/19
to sage-support
On Tuesday, October 22, 2019 at 8:52:44 AM UTC-7, david.guichard wrote:
I have a cocalc sage worksheet that reads data from a csv file. Is there any way to do this in the single cell server, that is, read data from an external file? I'm guessing not, but it would be handy.

Accessing a file from a single cell server should be possible via the normal means. Putting the file in a location where the single cell server has access to it is probably a problem. If you put the data at a publicly accessible http(s) location, you should be able to refer to the resource by its URL and fetch your data that way. Obviously, you should run pretty quickly into resource limitations put on sagecell processes. If you don't then you'll probably find that that particular sagecell server will be very unreliable, because it will be put out of commission by people running very resource-hungry processes on it.

david.guichard

unread,
Oct 22, 2019, 4:36:24 PM10/22/19
to sage-support
Thanks for the suggestion, but it doesn't appear to work for me. My code is

csv.reader(open('http://myserver/xxx.csv'))

and I have verified that the url is correct, but I get "No such file or directory: 'http://...'".
It works fine on a cocalc server with the csv file in the project the worksheet is in, and using just the local file name.

I did find a slightly more cumbersome way to do this using the Pandas data analyis library--there is a read_csv function that will read from a URL.

-- David

Nils Bruin

unread,
Oct 24, 2019, 3:01:34 PM10/24/19
to sage-support
On Tuesday, October 22, 2019 at 1:36:24 PM UTC-7, david.guichard wrote:
Thanks for the suggestion, but it doesn't appear to work for me. My code is

csv.reader(open('http://myserver/xxx.csv'))

I don't think python's standard "open" supports opening URLs. You need something like urllib.request for it (or indeed, a tool (for instance some Pandas routine) that wraps that functionality for you).
Reply all
Reply to author
Forward
0 new messages