Initialize and return a local Path instance. Path can be relative to the current directory. If path is None it defaults to the current working directory. If expanduser is True, tilde-expansion is performed. Note that Path instances always carry an absolute path.
(self, path=None, expanduser=False)
| 273 | sep = os.sep |
| 274 | |
| 275 | def __init__(self, path=None, expanduser=False): |
| 276 | class="st">"""Initialize and return a local Path instance. |
| 277 | |
| 278 | Path can be relative to the current directory. |
| 279 | If path is None it defaults to the current working directory. |
| 280 | If expanduser is True, tilde-expansion is performed. |
| 281 | Note that Path instances always carry an absolute path. |
| 282 | Note also that passing in a local path object will simply return |
| 283 | the exact same path object. Use new() to get a new copy. |
| 284 | class="st">""" |
| 285 | if path is None: |
| 286 | self.strpath = error.checked_call(os.getcwd) |
| 287 | else: |
| 288 | try: |
| 289 | path = os.fspath(path) |
| 290 | except TypeError: |
| 291 | raise ValueError( |
| 292 | class="st">"can only pass None, Path instances " |
| 293 | class="st">"or non-empty strings to LocalPath" |
| 294 | ) |
| 295 | if expanduser: |
| 296 | path = os.path.expanduser(path) |
| 297 | self.strpath = abspath(path) |
| 298 | |
| 299 | if sys.platform != class="st">"win32": |
| 300 |
nothing calls this directly
no test coverage detected