1

I have a folder structure as:

├── helper_files
│   ├── CONSTANTS.py
│   ├── bps.py
│   ├── bpsRestPy.py
│   └── helper.py
└── script_files
    ├── device_cleanup_script.py
    ├── device_sp_heavy_script.py
    ├── image_upload_script.py
    ├── profile_7_script.py
    ├── profile_9_script.py
    ├── shut_all_interfaces_script.py
    └── test.py

From test.py I want to access the helper.py, but the below one fails. Whats the correct way?

import sys
from pathlib import Path

path = str(Path(Path(__file__).parent.absolute()).parent.absolute())
sys.path.insert(0, path)

from helper_files import helper

helper.my_logger()
Akshay J
  • 5,362
  • 13
  • 68
  • 105

2 Answers2

0

try:

from ../helper_files import helper

it works for me

Hrushal
  • 45
  • 1
  • 9
0

Try this I hope this works.

import sys
sys.path.append(r'../helper_files') # relative path 

import helper

OR YOU COULD CHANGE THIS TO

import sys
sys.path.append(r'../')

from helper_files import helper

codester_09
  • 5,622
  • 2
  • 5
  • 27