Trees

A

Alex Le Dain

Is there a generic "tree" module that can enable me to sort and use
trees (and nodes). Basically having methods such as .AddNode(),
..GetAllChildren(), .FindNode() etc.

Is this handled natively with any of the core modules?

cheers, Alex.

--
Poseidon Scientific Instruments Pty Ltd
1/95 Queen Victoria St
FREMANTLE WA, AUSTRALIA

Ph: +61 8 9430 6639 Fx: +61 8 9335 4650
Website: www.psi.com.au

PSI, an ISO-9001 Company

CONFIDENTIALITY: The contents of this email (and any attachments) are
confidential and may contain proprietary and/or copyright material of
Poseidon Scientific Instruments Pty Ltd (PSI) or third parties. You may
only reproduce or distribute the material if you are expressly
authorised to do so. If you are not the intended recipient, any use,
disclosure or copying of this email (and any attachments) is
unauthorised. If you have received this email in error, please
immediately delete it and any copies of it from your system and notify
PSI by return email to sender or by telephone on +61 (08) 9430 6639.

DISCLAIMER: You may only rely on electronically transmitted documents when:
(a) those documents are confirmed by original documents signed by an
authorised employee of PSI; and/or
(b) the document has been confirmed and checked against a hard copy
of that document provided by PSI.

VIRUSES: PSI does not represent or warrant that files attached to this
e-mail are free from computer viruses or other defects. Any attached
files are provided, and may only be used, on the basis that the user
assumes all responsibility for any loss or damage resulting directly or
indirectly from such use. PSI's liability is limited in any event to
either the re-supply of the attached files or the cost of having the
attached files re-supplied.
 
F

Fuzzyman

Alex said:
Is there a generic "tree" module that can enable me to sort and use
trees (and nodes). Basically having methods such as .AddNode(),
.GetAllChildren(), .FindNode() etc.

Is this handled natively with any of the core modules?

cheers, Alex.

--
Poseidon Scientific Instruments Pty Ltd
1/95 Queen Victoria St
FREMANTLE WA, AUSTRALIA

Ph: +61 8 9430 6639 Fx: +61 8 9335 4650
Website: www.psi.com.au

PSI, an ISO-9001 Company

CONFIDENTIALITY: The contents of this email (and any attachments) are
confidential and may contain proprietary and/or copyright material of
Poseidon Scientific Instruments Pty Ltd (PSI) or third parties. You may
only reproduce or distribute the material if you are expressly
authorised to do so. If you are not the intended recipient, any use,
disclosure or copying of this email (and any attachments) is
unauthorised. If you have received this email in error, please
immediately delete it and any copies of it from your system and notify
PSI by return email to sender or by telephone on +61 (08) 9430 6639.

DISCLAIMER: You may only rely on electronically transmitted documents when:
(a) those documents are confirmed by original documents signed by an
authorised employee of PSI; and/or
(b) the document has been confirmed and checked against a hard copy
of that document provided by PSI.

VIRUSES: PSI does not represent or warrant that files attached to this
e-mail are free from computer viruses or other defects. Any attached
files are provided, and may only be used, on the basis that the user
assumes all responsibility for any loss or damage resulting directly or
indirectly from such use. PSI's liability is limited in any event to
either the re-supply of the attached files or the cost of having the
attached files re-supplied.

Long sig !! :)

Try elemtree by the F-bot....

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
 
D

Diez B. Roggisch

Alex said:
Is there a generic "tree" module that can enable me to sort and use
trees (and nodes). Basically having methods such as .AddNode(),
.GetAllChildren(), .FindNode() etc.


No. Usually, one uses the built-in python datastructures for this. E.g.

('root', [('child1', None), ('child2', None)])

Or writing a Node-class is also so straightforward that few care about them
being part of the core:

class Node(object):
def __init__(self, payload, childs=None):
self.payload = payload
self.childs = childs

def depth_first(self):
if self.childs:
for child in self.childs:
for node in child.depth_first():
yield node
yield self.payload



tree = Node('root', [Node('child1'), Node('child2')])

for n in tree.depth_first():
print n
 
N

Nick Coghlan

Diez said:
Or writing a Node-class is also so straightforward that few care about them
being part of the core:

Writing a *simple* node class is easy, but a full-featured one that supports
things like comparison and easy iteration is a bit more work. So various people
write partial implementations with only the features they need, and they all end
up being incompatible. So beyond being able to use it, the other thing is that
having an implementation in the standard library acts as a de facto interface
standard, making it easier to write common code to operate on tree structures.

All it would take to make it happen is a PEP, an implementation and a champion
with some persuasive ability :)

Cheers,
Nick.
 
D

Diez B. Roggisch

Writing a *simple* node class is easy, but a full-featured one that
supports things like comparison and easy iteration is a bit more work. So
various people write partial implementations with only the features they
need, and they all end up being incompatible. So beyond being able to use
it, the other thing is that having an implementation in the standard
library acts as a de facto interface standard, making it easier to write
common code to operate on tree structures.

Hm. I disagree on that. Some things make only sense for binary trees, others
need explicit uplinking to the parent node and so on. Some want accessor
methods, others have certain operator overloadings used for a specific
functionality. So in the end, it either becomes a monstrosity or is again
not usable. But that's only my HO.
All it would take to make it happen is a PEP, an implementation and a
champion with some persuasive ability :)

Go wild :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top