How to retrieve a module’s path?

import a_module print(a_module.__file__) Will actually give you the path to the .pyc file that was loaded, at least on Mac OS X. So I guess you can do: import os path = os.path.abspath(a_module.__file__) You can also try: path = os.path.dirname(a_module.__file__) To get the module’s directory.

How to deal with cyclic dependencies in Node.js

Try to set properties on module.exports, instead of replacing it completely. E.g., module.exports.instance = new ClassA() in a.js, module.exports.ClassB = ClassB in b.js. When you make circular module dependencies, the requiring module will get a reference to an incomplete module.exports from the required module, which you can add other properties latter on, but when you … Read more

What is __init__.py for?

It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”). Here’s the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory … Read more