A dunder is a variable surrounded by double underscores. Python is a special variable meant for unique usage and stores special information.
__file__ is a dunder in Python. It keeps the path to an imported Python module, and its value can be accessed as follows.
import math import random import numpy print(random.__file__) print(math.__file__) print(numpy.__file__)
The Python interpreter raises the following error if this variable is not defined.
NameError: global name __file__ is not defined
This article will learn how to resolve this error in Python.
NameError: global name __file__ is not defined Error in Python
This error arises when we try to access this variable inside the Python shell. All the code should be shifted to a Python file and executed using the following command from the terminal to fix this error.
python <file>.py <command line paramters>
- Can Only Concatenate List (Not Int) to List in Python
- Invalid Syntax in Python
- Value Error Need More Than One Value to Unpack in Python
- ValueError Arrays Must All Be the Same Length in Python
- Fix the TypeError: Object of Type 'Int64' Is Not JSON Serializable
- Fix the TypeError: 'float' Object Cannot Be Interpreted as an Integer in Python