Creating code to recall another script file. Before calling another script, I want to find out the name and path of the script I'm running right now, how do I do it?
For example,
Invoke script_1.py
-> script_2.py
Invoke script_2.py
-> script_3.py
script_3.py
-> Call Nothing
script_3
must find that script_3
is itself script_3
without passing the factor in script_2
os.getcwd()
could not be written by returning the path of the first script.
What else can I do?
The method of finding out your own name and your directory can be written as follows:
execfile("p2.py")
import inspect, os
print inspect.getfile(inspect.currentframe()) #path at p2.py
print os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # Directory to which p2.py belongs
© 2025 OneMinuteCode. All rights reserved.