[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 583: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 639: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
Gephi forums •libgexf python and unicode
Page 1 of 1

libgexf python and unicode

Posted: 31 Mar 2010 09:28
by paul
Hi dear gephi community,

My first post here so I start by a big Thank you to the all community of people around gephi and libgexf, you work rocks !

So I am starting to use libgexf through th python bindings.

I do have some nodes label which are unicode strings containing french accents.
When I try a

Code: Select all

data.setNodeLabel("id",myUnicodeString)
I got this error :
Traceback (most recent call last):
Traceback (most recent call last):
File "sqlToGexf.py", line 61, in ?
data.setNodeLabel(str(idNode),topic)
File "libgexf.py", line 776, in setNodeLabel
def setNodeLabel(self, *args): return _libgexf.Data_setNodeLabel(self, *args)
TypeError: in method 'Data_setNodeLabel', argument 3 of type 'std::string const &'
Ok now if I do this :

Code: Select all

data.setLabel("id",str(myUnicodeString))
it works till topic contains a unicode char (i.e. contains a french accent)
Traceback (most recent call last):
File "sqlToGexf.py", line 61, in ?
data.setNodeLabel(str(idNode),str(topic))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 2: ordinal not in range(128)
Of course I could get rid of accents but well I first want to be sure there's no way to keep my dear french accents ?

thank for your help

Paul

ps: I don't understand the difference between data.setLabel() and data.setNodeLabel()
the first one doesn't accept id, string as parameters... ?

Re: libgexf python and unicode

Posted: 31 Mar 2010 10:05
by paul
ok I found the way thanks to this very good link http://diveintopython.org/xml_processing/unicode.html

Code: Select all

data.setNodeLabel("id",myUnicodeString.encode("utf-8"))
Paul

Re: libgexf python and unicode

Posted: 31 Mar 2010 10:47
by admin
Hi Paul,

I don't see any data.setLabel() function (http://gexf.net/lib/api/functions_func.html#index_s). Where did you find it?