Function for the path of the script?

Ben Finney ben+python at benfinney.id.au
Sun Oct 27 00:10:11 EDT 2013


Peter Cacioppi <peter.cacioppi at gmail.com> writes:

> Am I the only one who finds this function super useful?
>
> def _code_file() :
>     return os.path.abspath(inspect.getsourcefile(_code_file))

I've used ‘os.path.dirname(os.path.abspath(__file__))’ to find the
directory containing the current file, in the past. But that was before
Python's ‘unittest’ module could discover where the test code lives.

> I've got one in every script. It's the only one I have to copy around.
> For my workflow ... so handy.

What workflow requires you to know the filename of the module, within
the module?

-- 
 \                              “Time wounds all heels.” —Groucho Marx |
  `\                                                                   |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list