Re: Reading from a GFile



Hi,

                   في س، 09-06-2012 عند 14:52 +0200 ، كتب Holger Berndt:
> Hello,
> 
> I'm trying to read from a GFile, but can't figure out how to do it.
> I neither found an answer in the tutorial, nor in PyGObject's tests or
> examples.

I think it's better to use load_contents (or load_contents_async)
instead of the lower level read.

$ echo "Test" > /tmp/tst
$ python
Python 2.7.3rc2 (default, Apr 22 2012, 22:35:38) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import Gio
>>> f = Gio.file_new_for_commandline_arg("/tmp/tst")
>>> f.load_contents(None)
(True, 'Test\n', '1339274639:0')

The second element is the file contents. (The first element is whether
the function succeeded, and should probably be removed in the override
file, and the last element is an etag, see Gio's documentation).

HTH,
Abderrahim



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