Python 2/3 and unicode file paths

21 October 2011

This bug popped up in a script of mine: For Python 2:
>>> os.path.abspath('.')
>>> os.path.abspath(u'.')
For Python 3:
>>> os.path.abspath('.')
>>> os.path.abspath(b'.')
That odd set of question marks is a completely useless and invalid path in case you were wondering. The windows cmd prompt sometimes has question marks that aren't garbage, but I assure you, these are useless and wrong question marks. The solution is to always use unicode strings with path functions. A bit of a pain. Am I the only one who thinks this is failing silently? I'll file it in the bug tracker and we'll see.