I have the following statement:
>>> sys.path.append(os.path.abspath(os.path.join(__file__, os.pardir, os.pardir)))
However, occasionally __file__
will not be defined in the namespace:
NameError: name '__file__' is not defined
What would be the best way to check for this? The first thing that came to mind was if '__file__' in globals()
.