[Tutor] problem calling a function

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sun Nov 13 11:33:56 CET 2005


Vincent Wan wrote:
> Dear all,
> 
> I have a simple program that calls a function I got off of active  
> state that draws
> a tree given a description of it in standard string form.
> 
> My code generates a string description and calls the function to draw  
> the tree.
> Instead of drawing the tree it echos the string. But when I call the  
> function
> interactively with the same string it prints the tree! Why dosn't it  
> work non-interactivly
> 
> here is my IDLE run
> 
> (((('0','9'),('4','6')),'2'),(('1',(('5','8'),'7')),'3'))
> (((('0','9'),('4','6')),'2'),(('1',(('5','8'),'7')),'3')) --
> 
>  >>> printDendrogram((((('0','9'),('4','6')),'2'),(('1', 
> (('5','8'),'7')),'3')))

printDendrogram accepts tuples, not strings:

>>> printDendrogram(((1, 2), (3, 4)))
1 --+
    |--+
2 --+  |
       |--
3 --+  |
    |--+
4 --+
>>> printDendrogram("((1, 2), (3, 4))")
((1, 2), (3, 4)) --

You'll have to modify your code so that it creates a tuple instead of a
string. I made it work by changing

printDendrogram(tree)

to

printDendrogram(eval(tree))

at the end of your code, but that's just a quick hack, not the
recommended way of doing things.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Tutor mailing list