【发布时间】:2021-07-08 18:43:46
【问题描述】:
import pathlib
home1 =pathlib.Path("/Users/sergii/Desktop/hello.txt")
print(f"home 1 is located {home1.cwd()}") #home 1 is located /Users/sergii/Documents
print(f"home 1 exists {home1.exists()}") #home 1 exists True
print(f"home 1 is a file {home1.is_file()}\n")
home2 = pathlib.Path("Desktop/hello.txt")
print(f"home 2 is located {home2.cwd()}") #home 2 is located /Users/sergii/Documents
print(f"home 2 exists {home2.exists()}") #home 2 exists False
print(f"home 2 is a file {home2.is_file()}")
【问题讨论】: