Last active
January 19, 2021 00:21
-
-
Save tshirtman/d8423695fe821440b65688b8dbd22b0c to your computer and use it in GitHub Desktop.
A function to load kv files automatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def load_kv(): | |
'''This magical function lookup module name, and load the kv file | |
with the same name (in the same directory) | |
''' | |
filename = inspect.currentframe().f_back.f_code.co_filename | |
f = extsep.join((splitext(filename)[0], 'kv')) | |
if exists(f) and f not in Builder.files: | |
Builder.load_file(f) | |
Nice! I am using
import pathlib
Builder.load_file(f'{pathlib.Path(__file__).parent.absolute()}{pathlib.os.sep}{pathlib.Path(__file__).stem}.kv')
in my python files. Works for python 3.7+ AFAIK.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting