[英]How to check if a PosixPath is a directory or a file
With Path
I can run path.is_dir()
, how can I do the same thing with PosixPath
?使用
Path
我可以运行path.is_dir()
,如何使用PosixPath
做同样的事情?
How can I do the same thing with
PosixPath
?如何使用
PosixPath
做同样的事情?
Exactly the same way.完全相同的方式。
PosixPath
extends Path
so has all the underlying methods: PosixPath
扩展了Path
,因此具有所有底层方法:
Python 3.9.0 (default, Oct 12 2020, 02:44:01)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib, os
>>> pathlib.PosixPath("/").is_dir()
True
>>> os.system("touch /tmp/aFile.txt")
>>> pathlib.PosixPath("/tmp/aFile.txt").is_dir()
False
>>> pathlib.PosixPath("/tmp/aFile.txt").is_file()
True
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.