When you create the file foo.py
, you create a python module. When you do import foo
, Python evaluates that file and places any variables, functions and classes it defines into a module object, which it assigns to the name foo
.
# foo.py
x = 1
def foo():
print 'foo'
>>> import foo
>>> type(foo)
<type 'module'>
>>> foo.x
1
>>> foo.foo()
foo
When you create the directory bar
with an __init__.py
file, you create a python package. When you do import bar
, Python evaluates the __init__.py
file and places any variables, functions and classes it defines into a module object, which it assigns to the name bar
.
# bar/__init__.py
y = 2
def bar():
print 'bar'
>>> import bar
>>> type(bar)
<type 'module'>
>>> bar.y
2
>>> bar.bar()
bar
When you create python modules inside a python package (that is, files ending with .py
inside directory containing __init__.py
), you must import these modules via this package:
>>> # place foo.py in bar/
>>> import foo
Traceback (most recent call last):
...
ImportError: No module named foo
>>> import bar.foo
>>> bar.foo.x
1
>>> bar.foo.foo()
foo
Now, assuming your project structure is:
main.py
DataFunctions/
__init__.py
CashAMDSale.py
def AMDSale(): ...
GetValidAMD.py
def ValidAMD(GetValidAMD): ...
your main
script can import DataFunctions.CashAMDSale
and use DataFunctions.CashAMDSale.AMDSale()
, and import DataFunctions.GetValidAMD
and use DataFunctions.GetValidAMD.ValidAMD()
.