-2

Function f in lib.py returns os.path.basename.

When I call f() from 1.py it returns me 'lib.py'. How can I modify f() so that it will return me '1.py'?

Артур Гудиев
  • 1,004
  • 2
  • 10
  • 26
  • 1
    You need to supply ut with the code you're using. `f()` is not a built in function. – Torxed Oct 01 '17 at 12:07
  • 1
    please add code snippet. – Harry Oct 01 '17 at 12:09
  • Are you asking how to find out which function has called `f` and output the file where that function is defined? If yes, that doesn't sound like a good idea - perhaps you could explain in more detail what you're trying to do. If no, well, what _are_ you asking? – Aran-Fey Oct 01 '17 at 12:13

1 Answers1

0

I guess, you need sys.argv[0] — a CLI argument #0 is the script being executed.

This also does not depend if it is called as python 1.py or ./1.py. For both cases, sys.executable can be used by find the python binary file. The script will always be argument #0.

It will be an empty string when called from an interactive mode, though. Because there is no script being executed.

Sergey Vasilyev
  • 3,919
  • 3
  • 26
  • 37