Graph library for Python

geremy condra debatem1 at gmail.com
Wed Dec 9 19:27:28 EST 2009


On Wed, Dec 9, 2009 at 7:02 PM, Rhodri James
<rhodri at wildebst.demon.co.uk> wrote:
> 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.

You're right, of course- the obvious way to do this is just to apply
tuple unpacking to each element in the edges argument. I've applied
the change, although testing and documentation will need to be
updated before I can merge it back into mainline, and I doubt I'll
get to that tonight.

Geremy Condra



More information about the Python-list mailing list