Python Module issues
Question: Im pretty new to python, and have been having a rough time learning it. I have
a main file

    
    
    import Tests
    from Tests import CashAMDSale
    
    CashAMDSale.AMDSale()
    

and CashAMDSale

    
    
    import pyodbc
    import DataFunctions
    import automa
    from DataFunctions import *
    from automa.api import *
    
    def AMDSale():
        AMDInstance = DataFunctions.GetValidAMD()
    

And here is GetValidAMD

    
    
    import pyodbc
    
    def ValidAMD(GetValidAMD):
         (short method talking to a database)
    

My error comes up on the line that has `AMDInstance =
DataFunctions.GetValidAMD()`

I get the error `AttributeError: 'module' object has no attribute
'GetValidAMD'`

I have looked and looked for an answer, and nothing has worked. Any ideas?
Thanks!


Answer: 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()`.

