Author VinsS
Recipients VinsS
Date 2011-09-16.17:50:13
SpamBayes Score 3.2407e-06
Marked as misclassified No
Message-id <1316195414.51.0.601610361957.issue12995@psf.upfronthosting.co.za>
In-reply-to
Content
Hi,

Trying this code:

------------------------------

# -*- coding: utf-8 -*-

import os
import sys
import platform

print('\nPython version: ', sys.version.split()[0])
print(platform.platform())


paths = ['/home/vincent/image.jpg', '/home/vincent/àéèîö.jpg']

for path in paths:
    print('\n', type(path))
    try:
        print(path)
    except UnicodeEncodeError as why:
        print('print > {0}'.format(why))
    try:
        if not os.path.exists(path):
            print('File not found!')
        else:
            print('File exists')
    except UnicodeEncodeError as why:
        print('os.path.exist > {0}'.format(why))
    try:
        stats = os.stat(path)
        print(stats.st_atime)
    except UnicodeEncodeError as why:
        print('os.stat > {0}'.format(why))
    try:
        f = open(path, 'b')
        f.close()
    except Exception as why:
        print('open > {0}'.format(why))

------------------------------------

on python 3.1.2:

------------------------------------
vincent@tiemoko:~/Python/oqapy/devel$ python3 test_string.py 

Python version:  3.1.2
Linux-2.6.32-33-generic-i686-with-Ubuntu-10.04-lucid

 <class 'str'>
/home/vincent/image.jpg
File exists
1316179838.94
open > Must have exactly one of read/write/append mode

 <class 'str'>
/home/vincent/àéèîö.jpg
File exists
1316179838.81
open > Must have exactly one of read/write/append mode
vincent@tiemoko:~/Python/oqapy/devel$ 

------------------------------------------------

on python 3.2.2:

------------------------------------------------
[vincent@myhost ~]$ python test_string.py

Python version:  3.2.2
Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_@_2.30GHz-with-glibc2.2.5
<class 'str'>
/home/vincent/image.jpg
File exists
1316187109.6772401
open > Must have exactly one of read/write/append mode and at most one plus
<class 'str'>
print > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
os.path.exist > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
os.stat > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
open > 'ascii' codec can't encode characters in position 14-18: ordinal not in range(128)
[vincent@myhost ~]$

-------------------------------------------------------------------


Any 'path = path.decode('utf-8')', 'encode(bhla)', 'sys.getfilesystemencoding()', 'magic_transform(abracadabra)'
don't change anythings.

Thanks for yours advice.

vince
History
Date User Action Args
2011-09-16 17:50:14VinsSsetrecipients: + VinsS
2011-09-16 17:50:14VinsSsetmessageid: <1316195414.51.0.601610361957.issue12995@psf.upfronthosting.co.za>
2011-09-16 17:50:13VinsSlinkissue12995 messages
2011-09-16 17:50:13VinsScreate