get the path of the script file in python

Solutions on MaxInterview for get the path of the script file in python by the best coders in the world

showing results for - "get the path of the script file in python"
Sara
21 Feb 2016
1# Python program get current working directory using os.getcwd()
2		
3# importing os module
4import os
5	
6# Get the current directory path
7current_directory = os.getcwd()
8	
9# Print the current working directory
10print("Current working directory:", current_directory)
11
12# Get the script path and the file name
13foldername = os.path.basename(current_directory)
14
15scriptpath = os.path.realpath(__file__)
16# Print the script file absolute path
17print("Script file path is : " + scriptpath)