未加星标

Writing in Python 3 has been a positive experience so far

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

As I've mentioned in passingbefore, I have a little python thing to log MIME attachment type information from Exim and I converted it from Python 2 to Python 3 about a month and a half ago. The direct reason for doing this was a relatively small one: the Python 3 version of the zipfile module could automatically handle ZIP archives (and tar files) that used XZ compression, which people were sending us. My indirect reason was that I haven't really done anything with Python 3 yet and it's clear to me that it's the future , so if I had an excuse it felt like it was time for me to get some experience.

The whole conversion went surprisingly smoothly. In large part this was because I'd written relatively clean modern Python code and I wasn't interpreting raw bytes off disk (or out of the network). Since I was mostly calling modules I could rely on them to do all of the hard work of thinking about Unicode; the actual change wound up being very small as a result. Of course that first pass involved some decisions that were kind of a hack, so I wound up having to do some real Unicode handling . I actually feel that this was a positive change for the code in general, since it forced me to think carefully about what I really wanted to do here instead of brushing it under the carpet of 'let's just spray random raw bytes at syslog and standard output'.

(Part of it is that doing the Python 3 equivalent of what I usually do here in Python 2 was just that little extra bit too much of a hack for me to accept.)

Python 3 character encoding issues were not painless and did force me to dosome digging. In an ideal world this would be better documented, but on the other hand I don't entirely mind having to do some code reading (but that's just me, other people could wind up more irritated). I feel, perhaps incorrectly, that wrestling with these issues here has made me better prepared to deal with similar ones in the future.

So overall I'd call this a complete success. Moving to Python 3 got me real benefits, caused me to clean up the code somewhat, and wasn't particularly painful. I now feel much more positive about doing more substantial work in Python 3 at some point, and just generally working with/in Python 3 in the future.

(I'm still unlikely to convert any of our existing Python code over to Python 3 unless I get some clear benefit from it, the way I did here. I'm not yet that attracted to Python 3, and besides my co-workers would rather that I left well enough alone.)

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: Python
分页:12
转载请注明
本文标题:Writing in Python 3 has been a positive experience so far
本站链接:http://www.codesec.net/view/485617.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(26)