Function for the path of the script?

Ben Finney ben+python at benfinney.id.au
Mon Oct 28 18:50:46 EDT 2013


Grant Edwards <invalid at invalid.invalid> writes:

> On 2013-10-27, Ben Finney <ben+python at benfinney.id.au> wrote:
>
> > What workflow requires you to know the filename of the module, within
> > the module?
>
> If you have a utility that can be used to do several related things,
> one way to tell that utility which you want to do is with command line
> arguments.

That's a case for inspecting the command line.

> For example your utility checks sys.argv[1] for a command or option
> flag. Another way is to give the file multiple names, and check
> sys.argv[0] to see what name you've been invoked under.

Exactly so. This isn't a use case for finding the filesystem location of
the module.

-- 
 \        “We have to go forth and crush every world view that doesn't |
  `\                believe in tolerance and free speech.” —David Brin |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list