0

I am making a programming language in Python called Simpl-Py. I want to add the capability for users to create modules and import them into my language. Instead of specifically importing a module, I want the program to check if there are any modules in a specific folder for modules only, and import them automatically. I know you can check to see if a file exists by trying to open the file, but in this case, the file name is unknown (because there could be many modules).

Could someone give me the syntax of how this would work?

Zer0 - Official
  • 35
  • 1
  • 2
  • 8
  • you can iterate over files in a directory with `os.walk` and some other methods https://stackoverflow.com/a/60966533/202168 ... `glob` could look for files in a dir by file extension https://docs.python.org/3/library/glob.html – Anentropic Apr 26 '22 at 15:34
  • Does [How to load all modules in a folder?](https://stackoverflow.com/questions/1057431/how-to-load-all-modules-in-a-folder) answer your question? – wwii Apr 26 '22 at 15:45
  • Another - [Python: how to import from all modules in dir?](https://stackoverflow.com/questions/16852811/python-how-to-import-from-all-modules-in-dir). If you browse through Q&A's searching with something lik `python import all modules in a folder site:stackoverflow.com` you will most likely find a way forward. After trying to implement you can ask or search for specific answers to problems you encounter. There is info in the Python documentation also. – wwii Apr 26 '22 at 15:53
  • @wwii thanks for the links, but remember, this is for my own programming language, not Python. These answers would work for importing Python modules into Python, but since I have a language made in Python, using other modules, these do not apply. – Zer0 - Official Apr 26 '22 at 16:01

0 Answers0