igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Re: Loading from a string or file IO object in Python


From: Chris Wj
Subject: Re: [igraph] Re: Loading from a string or file IO object in Python
Date: Thu, 5 Feb 2009 07:52:18 -0500

I like the sound of those Tamas. I think a combination of both may work well. Say all objects were converted in Python to a file object that could be read from C using fread (PyFile interface). Then in igraph it could expect either a string or a file as you said. I'll do some more code reading first as I want to look into the places that Gabor mentioned about where the temporary files are created. Then I'll experiment a bit with it probably tomorrow or the following day and report back.

-Chris

On Thu, Feb 5, 2009 at 4:48 AM, Tamas Nepusz <address@hidden> wrote:
1. Is 'PyString_AsString' portable?
Yes it is, because it merely converts between a Python string and a C-style string (more precisely, it returns a pointer to the internal storage area of a Python string -- this should be kept intact).

The real problem lies here (as Gabor stated):


2. I think the cString would not work, because 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. Chris, if you feel like you have the courage to patch the source code of the Python interface, go on ;) 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).

--
Tamas




_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


reply via email to

[Prev in Thread] Current Thread [Next in Thread]