high-energy-55500
05/24/2022, 1:58 AMpex_binary
? using __file__
as a starting point doesn’t work since all the files are running in pants’ temp directoryhundreds-father-404
05/24/2022, 2:00 AMPath("dir/write_me.txt")
high-energy-55500
05/24/2022, 2:14 AMwith open(Path("src/path/to/whatever.json"), "w") as f_:
json.dump(data, f_)
what if i didn’t know beforehand where the output would be, or wanted to write something relative to the file where a function is being called? Path(__file__).absolute()
unfortunately returns the file from the pantsdir and not the actual repohundreds-father-404
05/24/2022, 2:18 AMhigh-energy-55500
05/24/2022, 3:03 AMPath().joinpath("src", *__package__.split("."), "file.ext").absolute()
which works but feels weird and not at all like the right way to do things 😛 (and it also requires hardcoding in the src/
directory)bitter-ability-32190
05/24/2022, 10:26 AMsrc
.
Admittedly not greathundreds-father-404
05/24/2022, 12:11 PMbitter-ability-32190
05/24/2022, 12:13 PMrun
, but set the right PYTHONPATH?hundreds-father-404
05/24/2022, 12:14 PMbitter-ability-32190
05/24/2022, 12:17 PM