Python Forum
Import a module one step back of the path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import a module one step back of the path
#1
Hi I have the following file structure

Backend
|
--->Main --> app.py
|
--->package --> test.py

NOTE: Here Main and package directories are on the same level

Folder Structure Image

I want to import test.py in the app.py. Kindly help me how can we import this without using sys path
Reply
#2
Look at this post for advice.
So test folder and tests should advisable be outside of the package folder.
Then import stuff from package folder and test it outside of the package.
(Sep-21-2022, 09:31 AM)prathampatel9 Wrote: Kindly help me how can we import this without using sys path
Maybe you misunderstand how sys.path work,Python can not find anything whiteout it.
When make package so should project folder be in sys.path the will Python find package(all files and sub-folder) and test folder.
So Python only need to find the project folder,in example in post i make virtual environment(sys.path set as default to folder to project folder).
One more example A sample Python project.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  is import cointegration_analysis a recognized module mitcht33 1 424 Nov-06-2023, 09:29 PM
Last Post: deanhystad
  problem in import module from other folder akbarza 5 1,389 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  can not import anaconda pandas module. PySpark pandas module is imported!! aupres 0 713 Aug-06-2023, 01:09 AM
Last Post: aupres
  import module error tantony 5 3,438 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Import a module for use in type hint? Milosz 0 1,481 Nov-08-2021, 06:49 PM
Last Post: Milosz
  Can't install nor import delorean module Tek 3 2,795 Oct-27-2021, 03:32 AM
Last Post: Tek
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,198 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  import module with syntax error Skaperen 7 5,267 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  'import Path' do not understand how to use it tester_V 2 1,633 Jun-19-2021, 02:23 AM
Last Post: tester_V
  'urllib3' Module not found when import 'requests' spanz 5 10,182 Jan-06-2021, 05:57 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020