4

I have a module blah.time where I do some sanity checks and wrapper functions around normal time and date operations:

import time

def sleep(n):
    time.sleep(n)

When I call sleep, it just throws a maximum recursion error. I'm guessing the namespace is wrong, so I tried using import time as _time, but I still get the same error.

How do I reference the system time module from within my own module in order to prevent this namespace conflict?

3 Answers 3

14

Add from __future__ import absolute_import as the first line in your file.

This will force all imports to be absolute rather then relative. So import time will import the standard module, to import a local module you'd use from . import foobar

Sign up to request clarification or add additional context in comments.

Comments

3

I would read http://docs.python.org/whatsnew/2.5.html#pep-328-absolute-and-relative-imports and then use from __future__ import absolute_import.

HTH

Comments

0

What's happening is that your time module is shadowing the system time module. The easiest way around the problem is to rename your module to something besides time.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.