ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: What is the correct way to port codecs.open to python 3.1?
by Antoine Pitrou other posts by this author
Nov 7 2009 10:14AM messages near this date
Re: What is the correct way to port codecs.open to python 3.1? | Re: What is the correct way to port codecs.open to python 3.1?
Le Sat, 07 Nov 2009 12:56:54 +0100, Baptiste Lepilleur a écrit :
>  
>  After applying 2to3.py to port a 2.6 script to 3.1, I get the following
>  error when running my script:
>    File "purekeyworddbtest.py", line 143, in __init__
>      f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8')
>    File "c:\Python31\lib\codecs.py", line 870, in open
>      file = builtins.open(filename, mode, buffering)
>  ValueError: can't have text and binary mode at once

I would suggest not using codecs.open() in 3.x, since the built-in open() 
will do the same thing, but faster.

So just write:
    f = open(EXCLUDED_KEYWORDS_FILE, 'r', encoding='utf-8')
and you'll get a fast file object giving you str (unicode) objects after 
an implicit utf-8 decoding of file data.

Regards

Antoine.

-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Baptiste Lepilleur
Mrab
Antoine Pitrou
Baptiste Lepilleur

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved