In JavaScript, a module's default object can be set using "module.exports":
MyCache = require("./MyCache");
cache = new MyCache();
Similar behavior can be achieved in Python with:
from MyCache import Create as MyCache
cache = MyCache()
...but is it possible to set a default object in Python?
import MyCache
cache = MyCache()
No. When you import a module, you import a module. You can't make a module masquerade as something else. If you want to import a class, you can already do that very simply using from module import SomeClass
as in your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With