subZero
subZero

Reputation: 5176

Why do I have to write this import statement twice?

Here is my folder structure:

/ Thermal_Formatter
  Thermal_Formatter.py
  __init__.py

test.py

In Thermal_Formatter.py I have this method:

def processAndPrint(text):

in test.py this does NOT work:

import Thermal_Formatter
Thermal_Formatter.processAndPrint(something)

but this does:

import Thermal_Formatter.Thermal_Formatter
Thermal_Formatter.Thermal_Formatter.processAndPrint(something)

Why does it work when I write the module name twice, both in the import statement and the module call?

Upvotes: 2

Views: 160

Answers (1)

tayfun
tayfun

Reputation: 3135

Because Thermal_Formatter module is inside a package with same name. Try:

from Thermal_Formatter import Thermal_Formatter
Thermal_Formatter.processAndPrint(something)

If you want a more saner way to use it.

Upvotes: 5

Related Questions