Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79208
| Date | 2014-10-16 12:31 +0000 |
|---|---|
| From | Albert-Jan Roskam <fomcl@yahoo.com> |
| References | <CAPTjJmoJhE3UH2bwAUj1uqSxqHBbs6NONojcz-L_gS8fzSD6vQ@mail.gmail.com> |
| Subject | Re: what is the easiest way to install multiple Python versions? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14922.1413462820.18130.python-list@python.org> (permalink) |
----- 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)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: what is the easiest way to install multiple Python versions? Albert-Jan Roskam <fomcl@yahoo.com> - 2014-10-16 12:31 +0000
csiph-web