''' Assembles the name of a file called "x.txt" The literal string 'x' is used for this minimal example, but the issue was originally encountered taking an arbitrary name from argv and seeing if it needed an extension. ''' import os file_name = os.path.normcase('x') #"file_name = 'x'" fixes problem if not os.path.isfile(file_name): #"if True:" fixes problem x = file_name + '.txt' file_name = file_name + '.txt' #"file_name = file_name.encode('utf8').decode('utf8')" fixes problem print('file_name exists: ' + str(os.path.isfile(file_name))) print('x exists: ' + str(os.path.isfile(x))) print('file_name == x: ' + str(file_name == x))