2

How do I import every module and every method in project folder?

(Note: This is not production code, it's for debugging.)

Example:

How do I make this:

from views.display_hot_keys import display_hot_keys
from views.display_zones import display_zones
from controllers.api_key_controller import all_api_keys_nicknames
from models.api_data_standardizer import single_balance_standardizer

..become something like this...

from controllers.* import *
from views.* import *
from models.* import *

Edit: Perhaps I'm missing something, but I don't see how this question is answered in How can I get a list of locally installed Python modules??

Community
  • 1
  • 1
Emily
  • 2,129
  • 3
  • 18
  • 43
  • In theory, `*.*` would have imported _every python library_ if that worked. Meaning a whole bunch of features would be overwritten. For instance `json.dumps` and `pickle.dumps` would replace each other, `threading.enumerate` would replace `__builtins__.enumerate`. I understand that this isn't production code - but this feature wouldn't make sense to be a core feature of Python - So I doubt there's an easy way for this :) – Torxed Dec 17 '16 at 09:23
  • 1
    With that said, I'm voting to close this as a duplicate of http://stackoverflow.com/questions/739993/how-can-i-get-a-list-of-locally-installed-python-modules because the similarity in question and using those solutions and that information - you could build what you need. + [how to import modules from string](http://stackoverflow.com/questions/8718885/import-module-from-string-variable) – Torxed Dec 17 '16 at 09:24
  • You can make an imports script where you import everything. Just import that file into your main script. And then you can call all functions with this notation --> `import_script.function_name()` – Mohammad Yusuf Dec 17 '16 at 09:27
  • 1
    There's no easy way to do this, for a good reason. As the Zen of Python says, "Explicit is better than implicit". Using "star" imports is messy at the best of times because it floods your namespace with all of the imported names, but doing multiple star imports is a recipe for chaos since it makes it painful to figure out where each imported name came from, and as Torxed mentioned, you may get name collisions. – PM 2Ring Dec 17 '16 at 09:53
  • (cont) Star imports _can_ be useful, eg for quick hacking in the interactive interpreter, or when you want to define a bunch of names in separate modules but you want to make it look like they're all defined in one module. Otherwise, they're best avoided, IMHO. – PM 2Ring Dec 17 '16 at 09:53

0 Answers0