Posted By

silviud on 08/04/10


Tagged

python args


Versions (?)

python recurse for *args


 / Published in: Python
 

in case that you want to pass between multiple methods the same *args and unpack it at the end

  1. class Recurse:
  2.  
  3. last_t = []
  4.  
  5. def recurse(self,t):
  6. if not isinstance(t, tuple):
  7. self.last_t.append(t)
  8. else:
  9. for t1 in t:
  10. self.recurse(t1)
  11. return tuple(self.last_t)
  12.  
  13.  
  14.  
  15. d = ((((1,2,3,'test'),),),)
  16.  
  17. print Recurse().recurse(d)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: silviud on September 6, 2010

in case that you want to use the regular python way send the args unpacked as

callfoo(*argsunpacked)

You need to login to post a comment.