Is there something available in Python like PHP autoloader?

PythonServer Side ProgrammingProgrammingPHP

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.

raja
Published on 20-Dec-2017 16:31:06
Advertisements