python NameError: global name ‘__file__’ is not defined

This error comes when you append this line os.path.join(os.path.dirname(__file__)) in python interactive shell. Python Shell doesn’t detect current file path in __file__ and it’s related to your filepath in which you added this line So you should write this line os.path.join(os.path.dirname(__file__)) in file.py. and then run python file.py, It works because it takes your filepath.

NameError: global name ‘unicode’ is not defined – in Python 3

Python 3 renamed the unicode type to str, the old str type has been replaced by bytes. if isinstance(unicode_or_str, str): text = unicode_or_str decoded = False else: text = unicode_or_str.decode(encoding) decoded = True You may want to read the Python 3 porting HOWTO for more such details. There is also Lennart Regebro’s Porting to Python … Read more