Skip to content

My preset for a python package that makes importing quicker

Notifications You must be signed in to change notification settings

rp-bot/python-package-preset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-package-preset

My preset for a python package that makes importing less of a hassle

Features:

  • You can import anything from anywhere.
  • Import line in code is automatically updated, when the imported file is moved. (tested on vscode)

Package Directory's structure

[Main Parent Dir] <-- folder
├── __init__.py
├── any.py
├── [sub_dir_1] <-- folder
    ├── __init__.py
    ├── any.py
    ├── [another sub dir] <-- folder
        ├── __init__.py
        ├── any.py
|
├── [sub_dir_2] <-- folder
    ├── __init__.py
    ├── any.py
    ├── [another sub dir] <-- folder
        ├── __init__.py
        ├── any.py

__init__.py template

  • Folder level 0
# init file for folder level __
import os
import sys
currentdir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(currentdir)
  • Folder level 1
# init file for folder level 1
import os
import sys
currentdir = os.path.dirname(os.path.realpath(__file__))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)
  • Folder level 2
# init file for folder level 2
import os
import sys
                            # the deeper you go, the more times you'll have to call this function
currentdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)
  • Folder level 3 you probably don't need this?
# init file for folder level 3, 
import os
import sys
currentdir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)

About

My preset for a python package that makes importing quicker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages