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: Tamas Nepusz
Subject: Re: [igraph] Re: Loading from a string or file IO object in Python
Date: Thu, 5 Feb 2009 09:48:54 +0000

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





reply via email to

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