Python interface: make the graph import functions accept URLs or Python file objects

Bug #363705 reported by Tamás Nepusz
4
Affects Status Importance Assigned to Milestone
igraph
New
Undecided
Unassigned

Bug Description

Originally suggested by Chris Wj.

The igraph functions expect a FILE* and they want to call 'fread' (fscanf, etc.) on it. A possible way to go is to write the string to a temporary file and read that back -- another alternative is fmemopen() or open_memstream(), but we have to implement the temporary file solution anyway because of portability issues. [...] I have two possibilities in mind:

1. We could add another function to convert.c (say, igraphmodule_PyString_or_PyFile_to_fileptr()) that always returns an appropriate file pointer -- although we also have to take care of cleaning up the temporary file at some point.

2. We could simply override IO-related methods one level "above" in the Python layer (remember, the C layer implemeents igraph.core.GraphCore, igraph.Graph is inherited from that) to handle strings and files appropriately. This way we could maybe also handle URLs (i.e., if the string given is a URL, igraph could open a network connection and use the socket).

Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/384

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.