python how to run script in folder
Question: This is my python path:

    
    
    PYTHONPATH = D:\PythonPath
    

in the `PythonPath` folder I have `MyTests` folder that has a `Script.py`

in the `PyThonPath` folder I have `ScrapyingProject` folder

inside the `Script.py` I do this:

    
    
    from ScrapyingProject.ScrapyingProject.spiders.XXXSpider import XXXSpider
    

I got this exception:

    
    
    ImportError: No module named ScrapyingProjectScrapyingProject.spiders.XXXSpider
    

### Edit:

the XXXSpider is in this location:

    
    
    D:\PythonPath\ScrapyingProject2\ScrapyingProject2\spiders.py
    


Answer: Take a look at this to read more about Python modules and packages:
<http://docs.python.org/2/tutorial/modules.html>

Turn your python-script-containing folder into a python package by adding
`__init__.py` file to it. So, in your case, the directory structure should
resemble this:

    
    
    PYTHONPATH
    - ScrapyingProject
       - __init__.py
       - script.py
    

Now, in this scheme, `ScrappyProject` becomes your python-package. Any `.py`
file inside the folder becomes a python module. You can import a python module
by dot-expanded python path starting `PYTHONPATH`. Something like,

`from ScrapyingProject.script import XXXSpider`

Same logic can be extended by nesting multiple packages inside each other. A
nested package, for example looks like

    
    
    PYTHONPATH
    - ScrapyingProject2
       - __init__.py
       - ScrapyingProject2
           - __init__.py
           - script.py
    

Now, a package-nested script.py can be imported as

    
    
    from ScrapyingProject2.ScrapyingProject2 import script
    

Or even

    
    
    from ScrapyingProject2.ScrapyingProject2.script import XXXSpider
    

(Assuming you have defined `class XXXSpider` inside `script.py`)

