Message400075
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()
``` |
|
Date |
User |
Action |
Args |
2021-08-22 15:07:54 | cybergrind | set | recipients:
+ cybergrind |
2021-08-22 15:07:54 | cybergrind | set | messageid: <1629644874.28.0.329999889777.issue44979@roundup.psfhosted.org> |
2021-08-22 15:07:54 | cybergrind | link | issue44979 messages |
2021-08-22 15:07:54 | cybergrind | create | |
|