Is there something available in Python like PHP autoloader?


No there is not. And you should not try something like that in Python. There's a good reason for autoloading in PHP which is that PHP scripts are executed from scratch every time you load some page. The opcodes may be cached and files may be already prepared, but the main point remains - importing another file actually means making sure its contents are loaded.

In Python webservices, your files are not reread every time. If you import something, its imported for the lifetime of the app. Autoloaders in Python would be used only one time, not on each request.

So autoloaders in PHP potentially give you a benefit of skipping the cost of file loading where you don't need it. In Python, you just load stuff when the app starts and new requests do not need to load anything extra.

Updated on: 30-Jul-2019

211 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements