I want to combine multiple file maths together, but I end up with nested stuff like os.path.join(os.path.join(“assets”, “imgs”), “something.png”)
. I was wondering if there’s a cleaner way.
Asked
Active
Viewed 314 times
-1

NaniNoni
- 155
- 11
-
3I think this might be solved for using `reduce` or `split` (depending on the answer you look at): [Python os.path.join() on a list](https://stackoverflow.com/questions/14826888/python-os-path-join-on-a-list) – JNevill Jul 08 '22 at 15:18
-
There is also a [pathlib](https://docs.python.org/3/library/pathlib.html#module-pathlib) module in the standard library. – Thierry Lathuille Jul 08 '22 at 15:22
1 Answers
1
Try this:
os.path.join("assets", "images", "something.png")
'assets/images/something.png'

brunson
- 749
- 4
- 13