bpo-30618: add readlink to pathlib.Path (GH-8285) · python/cpython@a01ba33 (original) (raw)

Original file line number Diff line number Diff line change
@@ -1244,6 +1244,15 @@ def write_text(self, data, encoding=None, errors=None):
1244 1244 with self.open(mode='w', encoding=encoding, errors=errors) as f:
1245 1245 return f.write(data)
1246 1246
1247 +def readlink(self):
1248 +"""
1249 + Return the path to which the symbolic link points.
1250 + """
1251 +path = self._accessor.readlink(self)
1252 +obj = self._from_parts((path,), init=False)
1253 +obj._init(template=self)
1254 +return obj
1255 +
1247 1256 def touch(self, mode=0o666, exist_ok=True):
1248 1257 """
1249 1258 Create this file with the given access mode, if it doesn't exist.