Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

My answer was wrong.
Source Link
jedruniu
  • 528
  • 4
  • 13

If you are not sure about terminology go to very nice tutorials:

http://docs.python-guide.org/en/latest/writing/structure/#modules

and

http://docs.python-guide.org/en/latest/writing/structure/#packages

But for your structure:

.
├── job
│ └── the_script.py
└── modules
 ├── __init__.py
 └── print_module.py

just say in the the_script.py:

import sys
sys.append('..')
import modules.print_module

AndThis will add parent directory to PYTHONPATH, and python will see directory 'parallel' to job directory and it will work.

I think that at the most basic level it is sufficent to know that:

  1. package is any directory with __init__.py file
  2. module is a file with .py, but when you are importing module you omit extension.

If you are not sure about terminology go to very nice tutorials:

http://docs.python-guide.org/en/latest/writing/structure/#modules

and

http://docs.python-guide.org/en/latest/writing/structure/#packages

But for your structure:

.
├── job
│ └── the_script.py
└── modules
 ├── __init__.py
 └── print_module.py

just say in the the_script.py:

import modules.print_module

And it will work.

I think that at the most basic level it is sufficent to know that:

  1. package is any directory with __init__.py file
  2. module is a file with .py, but when you are importing module you omit extension.

If you are not sure about terminology go to very nice tutorials:

http://docs.python-guide.org/en/latest/writing/structure/#modules

and

http://docs.python-guide.org/en/latest/writing/structure/#packages

But for your structure:

.
├── job
│ └── the_script.py
└── modules
 ├── __init__.py
 └── print_module.py

just say in the the_script.py:

import sys
sys.append('..')
import modules.print_module

This will add parent directory to PYTHONPATH, and python will see directory 'parallel' to job directory and it will work.

I think that at the most basic level it is sufficent to know that:

  1. package is any directory with __init__.py file
  2. module is a file with .py, but when you are importing module you omit extension.
Source Link
jedruniu
  • 528
  • 4
  • 13

If you are not sure about terminology go to very nice tutorials:

http://docs.python-guide.org/en/latest/writing/structure/#modules

and

http://docs.python-guide.org/en/latest/writing/structure/#packages

But for your structure:

.
├── job
│ └── the_script.py
└── modules
 ├── __init__.py
 └── print_module.py

just say in the the_script.py:

import modules.print_module

And it will work.

I think that at the most basic level it is sufficent to know that:

  1. package is any directory with __init__.py file
  2. module is a file with .py, but when you are importing module you omit extension.
lang-py

AltStyle によって変換されたページ (->オリジナル) /