Answer
t.me/python_tesstОтвет:
Path at terminal when executing this file
D:\Python
This file path, relative to os.getcwd()
D:\Python\4.py
This file full path (following symlinks)
D:\Python\4.py
This file directory and name
D:\Python --> 4.py
This file directory only
D:\Python
Объяснение:
Модуль os предоставляет множество функций для работы с операционной системой, причём их поведение, как правило, не зависит от ОС, поэтому программы остаются переносимыми.
Код:
import os
print("Path at terminal when executing this file")
print(os.getcwd() + "\n")
print("This file path, relative to os.getcwd()")
print(__file__ + "\n")
print("This file full path (following symlinks)")
full_path = os.path.realpath(__file__)
print(full_path + "\n")
print("This file directory and name")
path, filename = os.path.split(full_path)
print(path + ' --> ' + filename + "\n")
print("This file directory only")
print(os.path.dirname(full_path))