Himanshu Mishra Himanshu Mishra - 1 year ago 83
Python Question

import types in python

I have a module named

which has the following code in it

def Hello():
return "Hello World"

But when I do

>>> import types
>>> types.Hello()

It gives me

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Hello'

This is really freaking me out.

Answer Source

types is a built-in module and import searches for a built-in module first before looking into local package.

>>> import types
>>> types
<module 'types' from '/usr/lib/python2.7/types.pyc'>


>>> from . import types