-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
43 lines (29 loc) · 1.06 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import __main__
import sys
import os
import json
from typing import List
APP_FOLDER_PATH = None
if ("pytest" in __main__.__file__):
APP_FOLDER_PATH = '.'
elif getattr(sys, 'frozen', False):
# If the application is run as a bundle, the PyInstaller bootloader
# extends the sys module by a flag frozen=True and sets the app
# path into variable _MEIPASS'.
APP_FOLDER_PATH = sys._MEIPASS
else:
APP_FOLDER_PATH = os.path.dirname(os.path.abspath(__main__.__file__))
def joinAppFolderPathAnd(subpath: str) -> str:
return os.path.join(APP_FOLDER_PATH, subpath)
def readFile(path):
with open(path, 'r', encoding='utf-8') as f:
return f.read()
def readFileFromAppFolder(fileName: str) -> str:
return readFile(joinAppFolderPathAnd(fileName))
def readJsonFile(filePath: str):
with open(filePath, 'r') as f:
return json.load(f)
def get_indexes(char: str, text: str) -> List[int]:
return [i for i, c in enumerate(text) if c == char]
def reverse(text: str) -> str:
return text[::-1]