Different class 'str' between v3.

Terry Reedy tjreedy at udel.edu
Sat Sep 17 00:30:03 CEST 2011


On 9/16/2011 9:52 AM, Vincent Vande Vyvre wrote:
> Testing the following code, I've differend return with python 3.1.2 and
> 3.2.2

running on two different machines with two different versions of Linux.

I get

> # -*- 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('\nPath: {0}, Type: {1}'.format(path, type(path)))
> if not os.path.exists(path) or not os.path.isfile(path):
> print('File not found: {0}'.format(path))
> else:
> print('File exists')

I get

Python version:  3.2.2rc1
Windows-7-6.1.7601-SP1

Path: /home/vincent/image.jpg, Type: <class 'str'>
File not found: /home/vincent/image.jpg

Path: /home/vincent/àéèîö.jpg, Type: <class 'str'>
File not found: /home/vincent/àéèîö.jpg

so

> [vincent at myhost ~]$ python string_2.py
>
> Python version: 3.2.2
> Linux-3.0-ARCH-x86_64-Pentium-R-_Dual-Core_CPU_T4500_ at _2.30GHz-with-glibc2.2.5
>
> Path: /home/vincent/image.jpg, Type: <class 'str'>
> File exists
> Traceback (most recent call last):
> File "string_2.py", line 13, in <module>
> print('\nPath: {0}, Type: {1}'.format(path, type(path)))
> UnicodeEncodeError: 'ascii' codec can't encode characters in position
> 21-25: ordinal not in range(128)

is not specific to 3.2.2 in general. Try the two Python versions on the 
same machine. Or try the test suite on each. See the test module doc for 
how.

-- 
Terry Jan Reedy





More information about the Python-list mailing list