/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
build_exe/pyinstaller_example/console/print_current_script_dir/main.py
34 строки
827 B
gil9red
Refactoring. Using black code style
25 апр 2023, 13:45
25 апр 2023, 13:45
ae2d7a4
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" # FROM: https://github.com/gil9red/SimplePyScripts/blob/927af3d3f05a0129338b21d074ca241c8a055118/get_current_script_dir.py import inspect import os import sys def get_current_script_dir(follow_symlinks=True, normcase=False) -> str: # py2exe, PyInstaller, cx_Freeze if getattr(sys, "frozen", False): path = os.path.abspath(sys.executable) else: # Analog inspect.getabsfile without os.path.normcase path = inspect.getframeinfo(inspect.currentframe()).filename path = os.path.abspath(path) if follow_symlinks: path = os.path.realpath(path) if normcase: path = os.path.normcase(path) return os.path.dirname(path) if __name__ == "__main__": print(get_current_script_dir())