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 character list to string 
Python :: try except python not working 
Python :: queue python 
Python :: python invert binary tree 
Python :: check if array is empty python 
Python :: with suppress python 
Python :: how to append items to a list in python 
Python :: dictionary to list python 
Python :: Python3 boto3 put and put_object to s3 
Python :: how to map longitude and latitude in python 
Python :: python check if website is reachable 
Python :: python pipe 
Python :: how to capitalize first letter in python 
Python :: mkvirtualenv environment python 3 
Python :: pandas print a single row 
Python :: python venv activate 
Python :: matplotlib orange line 
Python :: how to add textbox in pygame window 
Python :: numpy array split 
Python :: how to find the closest value in column python 
Python :: variable in python 
Python :: Reading JSON from a File with Python 
Python :: jupyter tabnine for jupyter notebook 
Python :: match python 3.10 
Python :: pandas legend placement 
Python :: turn python script into exe 
Python :: Compute the 2d histogram of x and y. 
Python :: decimal to binary in python 
Python :: how to dump a database using manage.py 
Python :: django only certain columns from database 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =