On 03/28/2013 01:52 PM, Daniele Zambelli wrote:
Ho un programma principale: main.py e una dir che contiene dei file:
mod0.py, ...
Il programma principale deve caricare tutte le funzioni presenti in
questi moduli, ma io vorrei anche avere una lista che le contiene.
Sono riuscito ad avere la lista con i loro nomi, ma mi serve la lista
con le funzioni.
for n_f in nfiles:
mod = __import__(n_f)
print(mod)
exenames = [e for e in dir(mod) if e.startswith('exe_')]
print(exenames)
Potresti usare il modulo inspect. Ad esempio:
import inspect
for n_f in nfiles:
mod = __import__(n_f)
attributes = [getattr(mod, name) for name in dir(mod)]
functions = [obj for obj in attributes if inspect.isfunction(obj)]
for f in functions:
print(f())
--
Marco Buttu
INAF Osservatorio Astronomico di Cagliari
Loc. Poggio dei Pini, Strada 54 - 09012 Capoterra (CA) - Italy
Phone: +39 070 71180255
Email: mbu...@oa-cagliari.inaf.it
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python