Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python get script name

# Option 1: Works for Python 3.4 +
from pathlib import Path
Path(__file__).name		# ScriptName.py
Path(__file__).stem		# ScriptName

# Option 2: use `os` library 
import os
os.path.basename(__file__)							# ScriptName.py
os.path.splitext(os.path.basename(__file__))[0]		# ScriptName
Comment

get the name of a current script in python

Use __file__. If you want to omit the directory part (which might be present), you can use os.path.basename(__file__)
Comment

PREVIOUS NEXT
Code Example
Python :: python list files in current directory 
Python :: use nltk to remove stop words 
Python :: create requirements.txt conda 
Python :: download files from google colab 
Python :: items of a list not in another list python 
Python :: mypy ignore type 
Python :: sorting by column in pandas 
Python :: horizontal line matplotlib python 
Python :: python list all csv in dir 
Python :: sqlalchemy query bilter by current month 
Python :: how to check sklearn version in cmd 
Python :: python saving a screentshot with PIL 
Python :: discord.py unban command 
Python :: split data validation python 
Python :: sort by index 2d array python 
Python :: flask code 
Python :: pycache in gitignore 
Python :: convert numpy to torch 
Python :: plotly hide legend 
Python :: not x axis labels python 
Python :: python reload module without restarting 
Python :: plot keras model 
Python :: how to find python location in cmd 
Python :: python gui programming using pyqt5 
Python :: python time.strptime milliseconds 
Python :: python setter getter deleter 
Python :: python 3 pm2 
Python :: how to set the screen brightness using python 
Python :: python auto clicker 
Python :: display python 001 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =