Python - print out a visual recursion trace -


I have this code which is doing recursion, but I want to be able to see the recycling, but every revision Explains the depth whenever it comes back just as simple as shown below. Not to be sure that I need to place an empty space or tab to make this space and I'm using a string map_str and then printing it to the end. Please see the code and output example.

  def get_process_parents (Bacdet, late-process): Global Der_prenents Global map_str process_depends = [] # logging.info ( 'late_process:% s'% late_process) process_depends = Getprocess dependence (Bacdet late -process) late_parents [late_process.get ('name')] = process_depends map_str + = ('% s --- & gt;% s \ n ------ & gt; \ n'% (late process. ('Name', get process_depends) # logging.info ('late_process name:% s --- & gt; depends:% s'% (late_process.get ('name'), process_depends)) Otherwise process_depends: # Logging.info ( 'and does not depend:% s'% late_process.get (' name ')) late_parents_process.add (late_process.get (' name ')) map_str + = ('% s --- & Gt; % S \ N ---- & gt; \ n '% (late_process.get (' name '), process_depends)): to process_depend in process_depends: process = getprocessByName (batchDate, process_depend) # logging.info (' process_depend % s - & Gt; state:% s '% (process_depend, process.get (' state ')) if process.get (' state ') ==' Done ': # logging.info (' Process: dependent (dependent) ):% S '% process_depend) map_str + = ('% s Status:% s \ n ---- & gt; \ n '% (process_depend, process.get (' state ')) Other: late_parents_process   

Output:

How do I want to see it?

Output:

/ P>

  process_name ----> ['Process Dependence 1', 'Process Dependence 2'] ------ & gt; Process dependency 1 ----> [Process Dependence 3, Dependency 4] ------ & gt; Dependency 3 ----- & gt; [] ------ & gt; Dependency 4 ----- & gt; [] ------ & gt; Process dependency 2 ----> [Process Dependence 5] ------ & gt; Process Dependencies 5 ----- & gt; [Process Dependence 6] ----- & gt; Process Dependency 6 ----- & gt; []    

Can you change the signature of the function? If so, then the easiest way to define the function as follows:

  def get_process_parents (batchdate, late work, depth = 0):   

and then your nested calls

  get_process_parents (Bacdet, getprocessByName (batchDate, process_depend), depth + 1)   

However, to indent, you can use Can:

  print '\ t' * Depth + ('% s ---- & gt; ... etc, etc.   

I use caution if you can avoid it then use the map_str for global use. Rudd.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -