ڕێکێن فایلان
ب Path پارچەیێن ڕێکەکێ پێکڤە گرێ بدە، دا کۆد ژ جوداهییا سیستەمان کێمتر کاریگەر ببیت.
د ڤێ لاپەڕێ دا
بیرۆکا وانەیێ
name بتنێ ناڤێ دووماهیێ ددەت.
نموونەیا کۆدی
فایلان دابگرە و ژ ZIP دەربێخە. ژ فولدەرا python_from_zero فەرمانێ بکار بینە. لسەر ویندۆزێ ل جهێ python3 بنڤیسە py.
python3 06_files_and_projects/43_paths/lesson.pyfrom pathlib import Path
from tempfile import TemporaryDirectory
print("Working directory:", Path.cwd())
print("Lesson directory:", Path(__file__).resolve().parent)
with TemporaryDirectory(prefix="python_paths_") as temporary:
folder = Path(temporary) / "notes"
folder.mkdir(parents=True, exist_ok=True)
file_path = folder / "lesson.txt"
file_path.write_text("Python", encoding="utf-8")
print(file_path.name, file_path.suffix, file_path.stem)
print(folder.exists(), folder.is_dir(), file_path.is_file())
print([path.name for path in folder.glob("*.txt")])ئەنجامی بشوپینە
بەرنامە ڕێکا شوینێ کارکرنێ و ڕێکا فایلێ ددەت. بۆ lesson.txt، name هەمی ناڤە، suffix پاشگرە و stem بەشێ بێ پاشگرە.
Working directory: <COURSE_ROOT>/06_files_and_projects/43_paths
Lesson directory: <COURSE_ROOT>/06_files_and_projects/43_paths
lesson.txt .txt lesson
True True True
['lesson.txt']هەڵەیەکا بەربەلاڤ
ڕێکا نسبی ژ فولدەرا کارکرنا ئێستا دەست پێ دکەت، نە هەمیشە ژ جهێ فایلێ پایتۆنێ.