what is the easiest way to install multiple Python versions?

Albert-Jan Roskam fomcl at yahoo.com
Thu Oct 16 08:31:29 EDT 2014


----- Original Message -----

> From: Chris Angelico <rosuav at gmail.com>
> To: 
> Cc: Python <python-list at python.org>
> Sent: Thursday, October 16, 2014 10:48 AM
> Subject: Re: what is the easiest way to install multiple Python versions?
> 

> On Thu, Oct 16, 2014 at 7:42 PM, Albert-Jan Roskam <fomcl at yahoo.com> 


<snip>

> The differences between 2.6 and 2.7 aren't great, though,
> so you may well be able to port it trivially. But in any case, so long
> as you have Wheezy, you should be able to run 2.6 the easy way.


Most things were indeed easy to solve. But this one surprised me. With Python 2.6, I need to outcomment the 'lambda' line. The error is what I get in Python 2.6. It does not matter if I do u"\n".join(het_logboek[i:]). I don't use latin-1 anywhere in my program. I need to convert unicode to bytes in Python 2.6, or else it chokes in the smart quote.


import codecs
import os
import time


def print_log_van_vandaag(logbestand):
    """Print today's log. The Cron Daemon will mail this"""
    vandaag = time.strftime("%Y-%m-%d")
    with codecs.open(logbestand, encoding="utf-8") as logboek:
        het_logboek = logboek.readlines()
        #het_logboek = map(lambda x: x.encode("utf-8"), het_logboek)  # bug in Python 2.6?
        for i, regel in enumerate(het_logboek):
            if regel.startswith(vandaag):
                print os.linesep.join(het_logboek[i:])
                break
Traceback (most recent call last):
File "mailer.py", line 410, in <module>
print_log_van_vandaag("mailer.log")
File "mailer.py", line 399, in print_log_van_vandaag
print os.linesep.join(het_logboek[i:])
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2018' in position 10214: ordinal not in range(256)



More information about the Python-list mailing list