0

There are many modules in a folder named schema

schema
   demo.py
   demo1.py
   xxx.py

my code here

import schema
for table in schema.__all__:
    do someting about table.xxx

I want to cyclic operate each module in schema, but table variable above code is a string, how can use the module with this table variable.

krock
  • 28,904
  • 13
  • 79
  • 85
廖前程
  • 101
  • 1
  • 1
  • 7
  • 1
    Possible duplicate of [Dynamic module import in Python](http://stackoverflow.com/questions/301134/dynamic-module-import-in-python) – Elisha Feb 18 '17 at 08:42
  • I'm not sure how good of an idea it is to rely on `__all__`, but you could always use `getattr(schema, table)` to return the actual attribute given a string from `table`. – juanpa.arrivillaga Feb 18 '17 at 08:52

0 Answers0