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'?
I guess, you need
sys.argv — 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.