w3resource

Python: Get the path and name of the file that is currently executing

Python Basic: Exercise-46 with Solution

Write a python program to get the path and name of the file that is currently executing.

Sample Solution:-

Python Code:

import os
print("Current File Name : ",os.path.realpath(__file__))

Sample Output:

Current File Name :  /home/students/fb6e28e0-2425-11e7-807b-bd9de91b1602.py 

Flowchart:

Flowchart: Get the path and name of the file that is currently executing.

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a python program to call an external command in Python.
Next: Write a Python program to find out the number of CPUs using.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]