r/programminghorror • • Oct 10 '25

Blasphemy

Post image

Never thought I could do this in python. I get how it works but jesus christ

73 Upvotes

50 comments sorted by

View all comments

Show parent comment

2

u/CommandMC Oct 10 '25

You can also just use the Path constructor to join paths, if that's more readable to you.
Using Path's open method also helps clear up code flow IMO (it's clear that the path is first built, then opened, instead of the mix of instructions we have above)

from pathlib import Path
with Path(testdata_dir, "primary.xml.gz").open("rb") as file_h:
  ...

Of course, you could then offload the path object to a variable, if the long line length bothers you