New submission from Kirill Pinchuk <cybergr...@gmail.com>:

Hi. I've been using this snippet for years and believe that it would be a nice 
addition to pathlib's functionality.

Basically, it allows constructing path relative to the current file (instead of 
cwd). Comes quite handy when you're working with deeply nested resources like 
file fixtures in tests and many other cases.

```
    @classmethod
    def relative(cls, path, depth=1):
        """
        Return path that is constructed relatively to caller file.
        """
        base = Path(sys._getframe(depth).f_code.co_filename).parent
        return (base / path).resolve()
```

----------
components: Library (Lib)
messages: 400075
nosy: cybergrind
priority: normal
severity: normal
status: open
title: pathlib: support relative path construction
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44979>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to