View Single Post
Old Nov 17th, 2006, 3:20 AM   #6
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Hm. It might help if you showed all your code, as it's difficult to understand exactly what you're asking for. Do you want some sort of persistence? Then you either need a functor:
python Syntax (Toggle Plain Text)
  1. class FindAllItemsFunctor
  2. def __init__(self):
  3. self.all_items = []
  4. def __call__(self, site):
  5. # Your find_all_items code using self.all_items instead of all_items
  6.  
  7. find_all_items = FindAllItemsFunctor()
Or you need to use some functions within functions:
python Syntax (Toggle Plain Text)
  1. def find_all_items_creater():
  2. all_items = []
  3. def find_all_items(site):
  4. # ...
  5. return find_all_items
  6.  
  7. find_all_items = find_all_items_creater()
Or you could use a global variable:
python Syntax (Toggle Plain Text)
  1. all_items = []
  2. def find_all_items(site):
  3. global all_items
  4. # ...
Or even do something clever with the function's parameters:
python Syntax (Toggle Plain Text)
  1. def find_all_items(site, all_items = [])
  2. # ...
Arevos is offline   Reply With Quote