Software

python 3.1 兼容问题一则:pickle 操作时文件读写模式

python 3升级变化颇多,这些天遇到不少,比如 pickle:

import pickle

shoplist = ['apple','food','noodle']

f = open('temp1.txt','wb')
pickle.dump(shoplist,f)
f.close()

f = open('temp1.txt','rb')
print(pickle.load(f))
f.close()

初始调试的时候,按照习惯设置打开模式为‘w’或者‘r’,报错:
Pickler(file, protocol, fix_imports=fix_imports).dump(obj)
TypeError: must be str, not bytes

搜索老外论坛得到原因:
For one thing, don't name your list "list", as that's a reserved word in Python (try list('12345') ), same thing with file... But that modification won't help you.

I'm assuming you've got a new version of Python installed, as the method you're using will only work in earlier versions of python.





pickle.dump(obj, file[, protocol, *, fix_imports=True])¶

Write a pickled representation of obj to the open file object file. This is equivalent to Pickler(file, protocol).dump(obj).

The optional protocol argument tells the pickler to use the given protocol; supported protocols are 0, 1, 2, 3. The default protocol is 3; a backward-incompatible protocol designed for Python 3.0.

Specifying a negative protocol version selects the highest protocol version supported. The higher the protocol used, the more recent the version of Python needed to read the pickle produced.

The file argument must have a write() method that accepts a single bytes argument. It can thus be a file object opened for binary writing, a io.BytesIO instance, or any other custom object that meets this interface.

If fix_imports is True and protocol is less than 3, pickle will try to map the new Python 3.x names to the old module names used in Python 2.x, so that the pickle data stream is readable with Python 2.x.
That's from the 3.1 docs; note that you must open your files in binary mode now. So for dumping use 'wb', and loading use 'rb'.

原来python 3以后必须使用模式‘wb’和‘rb’(load时)。

Python 3.1 主要语法笔记

1, ” 和 “” 完全一样
2, ‘’‘ 和“”“表示不带转义字符创
3, r’ 表示自然语法字符串(还不太明白)
4, 几个特殊运算符//, and ,or ,not,**
5,代码块用缩进表示,不用{}
6,函数定义
def functionName( p1,p2…pn=default):
缩进后表示函数体,无结束标志 More >

MAC的选择:Eclipse Galileo for Mac: Cocoa or Carbon?

Eclipse Galileo (3.5) is released today. Mac users downloading the new release will notice that, unlike previous releases, they have some interesting choices to make. They need to choose between “Mac OS X (Carbon)” and “Mac OS X (Cocoa)”. There’s also a third choice, which is currently not mainstream, the “Mac OS X (Cocoa) 64 bit”. So, which version is right for you?

More >

一步到位:黑莓9500/STORM混刷5.0 451rom

实测很稳定,电池续航提升很大,两天耗电两格,通话十分钟左右。

 

  1. 先混刷436rom(低版本先混合安装),教程见我前几天发的博文:http://www.chinaui.org/2010/01/269.html
  2. 下载451hhyperbrid rom,地址: http://www.bbhybrids.net/downloads.php?do=file&id=816&act=down
  3. 联机自动开始更新,按照提示正常完成。
  4. 451试用比较完美,特别是电池续航提升较大。

SONY PRS-600汉化方法

参见 http://bbs.pinyuew.com/viewthread.php?tid=361

黑莓上的计划管理工具 bbChecklist

如果GTD让你摸不著头脑,记事本太过简单,你只想要一个能简单做出计划和实施步骤后,有条不紊实施的简单软件,BBCHECKLIST就是你所需要的。用好它,你还有意想不到的收获。

bbChecklist is a simple, easy-to-use application for the BlackBerry that lets you create checklists for managing just about anything you can imagine. Some of the features of bbChecklist include:

  • Define multiple checklists with any number of steps.
  • Add dividers to your checklist to visually group steps together.
  • Enter notes for each step.
  • Cross-out a step if you want to skip it.

More >

2009年十大新兴企业技术:MapReduce折桂

cnbeta.com
对于《InfoWorld》来说,我们的一个任务就是从这个噪音中提取信号,从重要的东西中分离出对IT专业人员有重要价值的东西。我们都知道嗡嗡声是什么:是噪音。对于《InfoWorld》来说,我们的一个任务就是从这个噪音中提取信号,从重要的东西中分离出对IT专业人员有重要价值的东西。这是我们在评选2009年十大新兴企业技术的主旨。我们相信,对于IT行业来说,这次评选是一次盛宴,因为我们将评出大量有可能降低成本、改变我们 工作模式、开拓新领域的新技术。评选中,我们决定摒弃分析师们所鼓吹的高层次发展趋势,而是问我们自己:正在被交付,但是还没有被大范围采用的企业技术 中,哪些技术将会产生巨大影响?

More >

Gartner预测2012年十大手机应用 手机转账居首

新闻来源:新浪科技

Gartner今天评选出2012年10大手机应用,这一预 测是根据各类应用对消费者和业内企业的影响,并考虑收入、商业模式、消费者价值以及预期市场份额等多种因素评选出来的。
以下为Gartner预测的2012年十大手机应用:

1、手机转账

这种服务允许用户通过短信的方式给他人转账。与传统转账方式相比,其优点是便宜、快捷、便利。但是由于存在安全问题,这种服务将面临运营和政策 风险。

2、定位服务

这种服务可以判断用户所在位置,并据此提供一些衍生服务,例如广告信息和社交网络。

More >

矛与盾的较量,谁能胜出

今天在cnbeta看到kindle的DRM保护被破解的新闻。

=====================================================

kindledx有了DRM保护措施,用户就无法将Kindle上的内容随意共享到其他设备上。但是在今天以色列的程序员们突破了这一限制,他们找到了可以将Kindle上的内容拷贝到其他设备的方法。名为Labba的以色列黑客在某黑客论坛上发起了一次入侵Kindle的活动。

最终这些以色列程序员找到了突破DRM保护的方法,能将Kindle上面的电子书转换成开放格式和PDF格式,使得这些内容可以在其他电子阅读器上使用。相信Amazon很快就会修复该漏洞,但是Labba称,不管Amazon推出什么样的软件解决方案,他们将再次攻破——就像iPhone每次软件升级都被越狱一样。据悉,本次破解方法是基于去年已经公布的破解DRM的方法。

More >

Opera 10.5 抢鲜体验

我是Opera的忠实粉丝,一直以来习惯了Opera。传闻Opera 10.5即将在圣诞节前公布,作为圣诞献礼,于是在国外网站刨了一个泄露版的抢先体验下。

——————

Opera官方没有透露更多细节信息,只强调一点:Opera 10.5将装备最强大的JavaScript解码引擎Caracan,使Opera保持与其他浏览器产品同样的性能。

此番Alpha预览版中除了Caracan外,还采用了布局引擎Preson 2.5.18,以及整合最新的Windows 7特性,支持支持缩略图预览、Aero特效、跳跃菜单(快捷方式显示页面)。

在Opera 10.5界面顶端的左侧提供多种布局方式,取代原先的文件菜单目录,节省空间,可显示更多网页内容。同时,也支持在菜单栏显示下一级子菜单选项。

另一特色是在隐私模式下打开隐私标签页,该页面名称将显示绿色以区别于其他标签。一旦标签页关闭后,浏览器会自动删除所有相关的历史信息。类似的功能也出现在Chrome和Firefox中。

——————

安装截图

image

More >