Fully Qualified name of a python module

2019-07-21 06:45发布

问题:

In the code-base I am working on, the default python json module is being overridden by another json module which performs a different function.

How do I import the standard json module ?

import json does not work as it imports the other package.

What is the fully qualified name of the standard python json module ?

回答1:

Use absolute imports instead:

from __future__ import absolute_import
import json

You can still import the 'masking', local json module using the relative import syntax:

from . import json

Support for absolute imports as an option has been introduced in python 2.5, and is the default in python 3.

It'd be better to rename the 'masking' module, however.