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 import opencv in python 
Python :: import django value 
Python :: sort dictionary by value and then key python 
Python :: types of dict comprehension 
Python :: who created python 
Python :: numpy aray map values with dictionary 
Python :: backtracking python 
Python :: bucketizer pyspark 
Python :: extends template django 
Python :: (for in) printing in python 
Python :: how to make a nan value in a list 
Python :: how to create a variable in python 
Python :: msg.author discord.py 
Python :: flask decoding base 64 image 
Python :: how to loop through string in python 
Python :: python offline translate pypi 
Python :: slice notation python 
Python :: python not equal multiple values 
Python :: dataframe to dictionary using index as key 
Python :: default orange and blue matplotlib 
Python :: python get the app path 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =