6 May
2018
6 May
'18
5:44 p.m.
On Mon, May 7, 2018 at 1:05 AM, George Fischhof
On Sun, May 6, 2018, 1:54 AM Yuval Greenfield
wrote: Hi Ideas,
I often need to reference a script's current directory. I end up writing:
import os SRC_DIR = os.path.dirname(__file__)
I would give +1 for __dirname__
Something to keep in mind: making this available to every module, whether it's wanted or not, means that the Python interpreter has to prepare that just in case it's wanted. That's extra work as part of setting up a module. Which, in turn, means it's extra work for EVERY import, and consequently, slower Python startup. It might only be a small slowdown, but it's also an extremely small benefit. -1. ChrisA