Contoh program : Program Python untuk Mendapatkan Jalur Lengkap dari Direktori Kerja Saat Ini

0
(0)

Contoh 1: Menggunakan modul pathlib

import pathlib

// path of the given file
print(pathlib.Path("my_file.txt").parent.absolute())

// current working directory
print(pathlib.Path().absolute())

Keluaran

/Users/username
/Users/username

Contoh 2: Menggunakan modul os

import os

// path of the given file
print(os.path.dirname(os.path.abspath("my_file.txt")))

// current working directory
print(os.path.abspath(os.getcwd()))

Keluaran

/Users/username
/Users/username

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.