I am new to Python and recently I am working on Shell Scripting. In Shell Scripting if I want to pass filename to variable then I am passing like
myScriptName="`/bin/basename $0`"
Is it possible to same in Python??
I am new to Python and recently I am working on Shell Scripting. In Shell Scripting if I want to pass filename to variable then I am passing like
myScriptName="`/bin/basename $0`"
Is it possible to same in Python??
If you don't care about path of the file:
You can use a call to OS method __file__
to accomplish this. This will bring in extension also.
import os
fileName = os.path.basename(__file__)
print fileName
If you want full path with filename assigned to a variable:
import sys
file2= sys.argv[0]
print file2