Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79208 > unrolled thread

Re: what is the easiest way to install multiple Python versions?

Started byAlbert-Jan Roskam <fomcl@yahoo.com>
First post2014-10-16 12:31 +0000
Last post2014-10-16 12:31 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: what is the easiest way to install multiple Python versions? Albert-Jan Roskam <fomcl@yahoo.com> - 2014-10-16 12:31 +0000

#79208 — Re: what is the easiest way to install multiple Python versions?

FromAlbert-Jan Roskam <fomcl@yahoo.com>
Date2014-10-16 12:31 +0000
SubjectRe: what is the easiest way to install multiple Python versions?
Message-ID<mailman.14922.1413462820.18130.python-list@python.org>
----- Original Message -----

> From: Chris Angelico <rosuav@gmail.com>
> To: 
> Cc: Python <python-list@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@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)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web