libgexf python and unicode

General support of the libgexf dynamic library.
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
paul
Posts:31
Joined:31 Mar 2010 08:44
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
libgexf python and unicode

Post by paul » 31 Mar 2010 09:28

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... ?

paul
Posts:31
Joined:31 Mar 2010 08:44
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: libgexf python and unicode

Post by paul » 31 Mar 2010 10:05

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

admin
Gephi Community Manager
Posts:964
Joined:09 Dec 2009 14:41
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: libgexf python and unicode

Post by admin » 31 Mar 2010 10:47

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?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable