Module inside module error, python
Question: I created a File named StringPlay.py, and called it upon a file ScanTheFile.py
then called a function in ScanTheFile.py in another file named Controller.py.
But it raise an error that StringPlay.py does not exist

In ScanTheFile.py

    
    
    import StringPlay as SP
    
    def TNews(FileFirstLine):
        FileLine = SP.RemoveSpases(FileFirstLine)
        if True:
           Statement
        return(FileLine)
    

In Controller.py

    
    
    from HelpFiles import StringPlay as SP
    from HelpFiles import ScanTheFile as StF
    
    File1 = open("TextFiles\File1.txt")
    print(Stf.TNews(File1.readline()))
    

When this is executed it raises a Message Stating that in ScanTheFile.py in
Line 1:

    
    
    File "C:\Users\***\My Documents\Python\HelpFiles\ScanTheFile.py", line 1, in <module>
    import StringPlay as SP
    ImportError: No module named 'StringPlay'
    

But when ScanTheFile.py is being executed there's no problem.

This is my directory structure

    
    
    My Documents\Python 
    My Documents\Python\Controller.py 
    My Documents\Python\HelpFiles 
    My Documents\Python\HelpFiles\ScanTheFile.py 
    My Documents\Python\HelpFiles\StringPlay.py 
    My Documents\Python\TextFiles 
    My Documents\Python\TextFiles\File1.txt 
    My Documents\Python\TextFiles\File2.txt
    


Answer: You are having this problem because when you run `Controller.py` you are
running it in say `C:\...\My Documents` when you call `from HelpFiles import
ScanTheFile as StF` you are telling python to look in `C:\...\My
Documents\HelpFiles` for a file named `ScanTheFile.py`.

It finds this file and runs it _in`C:\...\My Documents`_ so when it hits the
line in `ScanTheFile.py`:

    
    
    import StringPlay as SP
    

it looks in `C:\...\My Documents` for `StringPlay.py` which from what I can
gather exists in `C:\...\My Documents\HelpFiles`.

Since you are already importing `StringPlay.py` explicitly in `Controller.py`
I would say just change `ScanTheFile.py` to only import `StringPlay.py` when
it is the file being run directly, and not imported:

`ScanTheFile.py`

    
    
    if __name__ == "__main__":
        import StringPlay as SP
    
    def TNews(FileFirstLine):
        FileLine = SP.RemoveSpases(FileFirstLine)
        if True:
           Statement
        return(FileLine)
    

