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
__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
JustMyModule and store it as a
Now let’s create another file named GFG.py that imports the above created module to show the use of
- __name__ (A Special variable) in Python
- Python program to reverse the content of a file and store it in another file
- reStructuredText | .rst file to HTML file using Python for Documentations
- Create a GUI to convert CSV file into excel file using Python
- Special Keys in Selenium Python
- Python - Get file id of windows file
- Protected variable in Python
- tensorflow.math.special.dawsn() function in Python
- tensorflow.math.special.fresnel_cos() function in Python
- tensorflow.math.special.spence() function in Python
- tensorflow.math.special.fresnel_sin() function in Python
- tensorflow.math.special.expint() function in Python
- Python | Check if a variable is string
- Python | Check if variable is tuple
- Python | Variable list slicing
- Operations on Graph and Special Graphs using Networkx module | Python
- Print Single and Multiple variable in Python
- Different ways to access Instance Variable in Python
- Python Program to swap two numbers without using third variable
- Python | Set 6 (Command Line and Variable Arguments)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.