__file__ (A Special variable) in Python Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report A double underscore variable in Python is usually referred to as a dunder. A dunder variable is a variable that Python has defined so that it can use it in a "Special way". This Special way depends on the variable that is being used. Note: For more information, refer to Dunder or magic methods in Python The __file__ variable: __file__ is a variable that contains the path to the module that is currently being imported. Python creates a __file__ variable for itself when it is about to import a module. The updating and maintaining of this variable is the responsibility of the import system. The import system can choose to leave the variable empty when there is no semantic meaning, that is when the module/file is imported from the database. This attribute is a String. This can be used to know the path of the module you are using. To understand the usage of __file__ consider the following example. Example: Let's create a module named HelloWorld and store it as a .py file. python # Creating a module named # HelloWorld def hello(): print("This is imported from HelloWorld") # This code is improved by gherson283 Now let's create another file named GFG.py that imports the above-created module to show the use of __file__ variable. python # Importing the above # created module import HelloWorld # Calling the method # created inside the module HelloWorld.hello() # printing the __file__ # variable print(HelloWorld.__file__) Output: Comment More infoAdvertise with us Next Article __file__ (A Special variable) in Python V vijaysouri4 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2019 python-utility Practice Tags : python Similar Reads __name__ (A Special variable) in Python Since there is no main() function in Python, when the command to run a python program is given to the interpreter, the code that is at level 0 indentation is to be executed. However, before doing that, it will define a few special variables. __name__ is one such special variable. If the source file 2 min read Get Variable Name As String In Python Getting a variable name as a string in Python means finding the label that points to a specific value. For example, if x = "Python", we can loop through globals() or locals() and compare values using the is operator to find that the name x points to "Python". Letâs explore some simple and effective 2 min read How To Print A Variable's Name In Python In Python, printing a variable's name can be a useful debugging technique or a way to enhance code readability. While the language itself does not provide a built-in method to directly obtain a variable's name, there are several creative ways to achieve this. In this article, we'll explore five simp 3 min read Viewing all defined variables in Python In this article, we are going to discuss how to view all defined variables in Python. Viewing all defined variables plays a major role while debugging the code. Method 1: Using dir() function dir() is a built-in function to store all the variables inside a program along with the built-in variable fu 5 min read Copy And Replace Files in Python In Python, copying and replacing files is a common task facilitated by modules like `shutil` and `os`. This process involves copying a source file to a destination location while potentially replacing any existing file with the same name. Leveraging functions like `shutil.copy2` and `os.remove`, thi 2 min read Like