Take the 2-minute tour ×

Possible Duplicate:
How to access a standard-library module in Python when there is a local module with the same name?

I'm using Python 2.6.

I only use absolute imports in my application. Now I have this:

   -- myscript 
   -- json
         -- anotherscript.py

In myscript, I have:

import json
import myapp.json.anotherscript

Because of Python relative import mechanism, import json does not import the built-in library as I want, but my custom json package into current namespace.

Is there a way to disable relative imports in Python or at least a hack to avoid it in this case? Otherwise, i'll have to rename my package to something else that does not make so much sense as jsonutils.

Thanks in advance.

share|improve this question

marked as duplicate by Yuval Adam, Deestan, Shawn Chin, Junuxx, C. Ross Nov 5 '12 at 15:34


Why do you want to avoid from . import json? That syntax was introduced to solve your problem! Anyway, as a rule, never ever name a module like a built-in. –  Bakuriu Nov 5 '12 at 14:26
add comment

1 Answer

up vote 8 down vote accepted
from __future__ import absolute_import

Described in PEP-328

share|improve this answer
AKA from __ruby__ import require_relative –  Colonel Panic Nov 5 '12 at 14:38
add comment
