"Serge Orlov" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> I've never used tkinter, but I heard good things about it. Are you > sure it's not you who made it to return byte string sometimes? Yes, I used a Tkinter.StringVar to keep track of the contents of an Entry widget; as long as I entered only ascii characters get() returns a byte string, as soon as a special character is entered it returns unicode. Anyway, my UnicodeVar() class seems to be a handy way to avoid problems here. > > > 4. in order to maintain code readability it's better to risk excess > > decode/encode cycles than having one too few. > > I don't think so. Either you need decode/encode or you don't. I use a bunch of modules that contain helper functions for frequently repeated tasks. So it sometimes happens for example that I call one of my module functions to convert user input into unicode and then call the next module function to convert it back to byte string to start some file operation; that's what I meant with "excess decode/encode cycles". However, trying to avoid these ended in totally messing up the code. > > 5. file operations seem to be delicate; > > You should be ready to handle unicode errors at file operations as > well as for example ENAMETOOLONG error. Any file system with path > argument can throw it, I don't think anything changed here with > introduction of unicode. For example access can return 11 (on > my linux system) error codes, consider unicode error to be twelveth. > > > at least I got an error when I > > passed a filename that contains special characters as unicode to > > os.access(), so I guess that whenever I do file operations > > (os.remove(), shutil.copy() ...) the filename should be encoded back > > into system encoding before; > > I think python 2.3 handles that for you. (I'm not sure about the > version) > If you have to support older versions, you have to do it yourself. I am using python-2.3.4 and get unicode errors: >>> f = os.path.join(u'/home/pingu/phonoripper', u'\xc3\u20ac') >>> os.path.isfile(f) True >>> os.access(f, os.R_OK) Traceback (most recent call last): File "<stdin>", line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode characters in position 24-25: ordinal not in range(128) >>> f = f.encode('iso-8859-15') >>> os.access(f, os.R_OK) True >>> Thanks for the feedback Michael -- http://mail.python.org/mailman/listinfo/python-list