Skip to content

Instantly share code, notes, and snippets.

@kaypee90
Last active February 14, 2021 12:07
Show Gist options
  • Save kaypee90/bc21668719480aa2146829137d714055 to your computer and use it in GitHub Desktop.
Save kaypee90/bc21668719480aa2146829137d714055 to your computer and use it in GitHub Desktop.
Python Import Tips

In a folder trying to import from another folder at the same level

example
=========

|   --   module1/
|    |   --   sample1.py
|
|   --   module2/
|     |   --   sample2.py

  • Trying to import into sample1.py from sample2.py
  • Add this to the top of the sample1.py
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment