MCPcopy Index your code
hub / github.com/python/cpython / Path

Class Path

Lib/pathlib/__init__.py:819–1480  ·  view source on GitHub ↗

PurePath subclass that can make system calls. Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiat

Source from the content-addressed store, hash-verified

817
818
819class Path(PurePath):
820 """PurePath subclass that can make system calls.
821
822 Path represents a filesystem path but unlike PurePath, also offers
823 methods to do system calls on path objects. Depending on your system,
824 instantiating a Path will return either a PosixPath or a WindowsPath
825 object. You can also instantiate a PosixPath or WindowsPath directly,
826 but cannot instantiate a WindowsPath on a POSIX system or vice versa.
827 """
828 __slots__ = ('_info',)
829
830 def __new__(cls, *args, **kwargs):
831 if cls is Path:
832 cls = WindowsPath if os.name == 'nt' else PosixPath
833 return object.__new__(cls)
834
835 @property
836 def info(self):
837 """
838 A PathInfo object that exposes the file type and other file attributes
839 of this path.
840 """
841 try:
842 return self._info
843 except AttributeError:
844 self._info = _Info(str(self))
845 return self._info
846
847 def stat(self, *, follow_symlinks=True):
848 """
849 Return the result of the stat() system call on this path, like
850 os.stat() does.
851 """
852 return os.stat(self, follow_symlinks=follow_symlinks)
853
854 def lstat(self):
855 """
856 Like stat(), except if the path points to a symlink, the symlink's
857 status information is returned, rather than its target's.
858 """
859 return os.lstat(self)
860
861 def exists(self, *, follow_symlinks=True):
862 """
863 Whether this path exists.
864
865 This method normally follows symlinks; to check whether a symlink exists,
866 add the argument follow_symlinks=False.
867 """
868 if follow_symlinks:
869 return os.path.exists(self)
870 return os.path.lexists(self)
871
872 def is_dir(self, *, follow_symlinks=True):
873 """
874 Whether this path is a directory.
875 """
876 if follow_symlinks:

Callers 15

check-epub.pyFile · 0.90
get_diff_filesFunction · 0.90
fail_if_regressionFunction · 0.90
mainFunction · 0.90
inject_traceFunction · 0.90
write_glossary_jsonFunction · 0.90
runMethod · 0.90
patchlevel.pyFile · 0.90
init_annotationsFunction · 0.90
android.pyFile · 0.90
delete_globFunction · 0.90
configure_host_pythonFunction · 0.90

Calls 1

sliceClass · 0.85

Tested by 15

test_issue44061Method · 0.72
make_moduleMethod · 0.72
__init__Method · 0.72
find_pyMethod · 0.72
py_iniMethod · 0.72
scriptMethod · 0.72
test_versionMethod · 0.72
test_list_pathsMethod · 0.72
test_search_pathMethod · 0.72
test_search_path_exeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…