#!/usr/bin/python #encoding=utf-8 class test(object): x = u"filename.dat" def __str__(self): print "str" return str(self.x) def __unicode__(self): print "unicode" return unicode(self.x) t = test() import os os.stat(t) ------------------ Traceback (most recent call last): File "test.py", line 19, in os.stat(t) TypeError: coercing to Unicode: need string or buffer, test found