This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Different behaviours with between v3.1.2 and v3.2.2
Type: Stage:
Components: Unicode Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: VinsS, benjamin.peterson
Priority: normal Keywords:

Created on 2011-09-16 17:50 by VinsS, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg144143 - (view) Author: Vincent Vande Vyvre (VinsS) Date: 2011-09-16 17:50
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
msg144145 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-09-16 18:07
This is because how the filesystem encoding is determined has changed. You probably need to explicity discover how non-ascii characters like those in '/home/vincent/àéèîö.jpg' are encoded in your filesystem.
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57204
2011-09-16 18:07:33benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg144145

resolution: not a bug
2011-09-16 17:50:13VinsScreate