Graph library for Python

Rhodri James rhodri at wildebst.demon.co.uk
Wed Dec 9 19:02:22 EST 2009


On Wed, 09 Dec 2009 23:42:13 -0000, geremy condra <debatem1 at gmail.com>  
wrote:

> On Wed, Dec 9, 2009 at 6:04 PM, Rhodri James
> <rhodri at wildebst.demon.co.uk> wrote:
>> On Wed, 09 Dec 2009 03:47:03 -0000, geremy condra <debatem1 at gmail.com>
>> wrote:

>>> g = Graph(
>>>    nodes={'a':{'colour':'red'},
>>>               'b':{'colour':'white'},
>>>               'c':{'colour':'blue'}},
>>>    edges={('a', 'b'):{'name':'ab', 'weight':2},
>>>               ('a', 'c'):{'name':'ac'},
>>>               ('b', 'c'):{'name':'bc', 'style':'dotted'}}
>>> )
>>
>> That's OK for nodes, but for consistency with add_edges I would have
>> expected the name to be the optional third element of the key tuples.  
>>  It
>> works either way, but I can't help feel it's beginning to look a bit  
>> ugly.
>
> I have to admit, I prefer it the other way, but patrick (our test guru  
> and
> chief bug squasher) likes your proposal better. I'm going to get in touch
> with robbie tonight and see what he says. Since this is not a feature  
> I'll
> use much, if he agrees with you then I'll go ahead and implement the
> change tonight and merge it back into mainline. If not, I'd appreciate
> it if you'd take another look at it and figure out if its something you  
> can
> live with, or if theres another syntax you'd prefer, etc. Fair enough?

Fair enough.  Don't take my word as having much weight; I'm not likely to  
use graphs much for graph theory purposes (having skipped the topology  
courses in the Maths part of my degree), it just happens to be clearly the  
right datastructure for a project I'm fiddling with at home.

Here's a thought: are

   g.add_edge("a", "b", "ab")

and

   g.add_edge("a", "b", name="ab")

equivalent?  If so, there's no reason not to have both forms of the  
initialiser.  If not, that weighs against having 'name' as a dictionary  
key.

-- 
Rhodri James *-* Wildebeest Herder to the Masses



More information about the Python-list mailing list