
Python
chienchia
自在不成人,成人不自在
展开
-
更新mac下自带的python2.7到python3.3
mac lion自带的python是2.7版本的,有点儿低,要使用一些应用的时候还需要3.3以上的,这时可以用以下的方法更新mac自带的python。先去python的官网下载最新的python,并安装好。现在要删除mac自带的python,如下:sudo rm -R /System/Library/Frameworks/Python.framework/Versions/2.7转载 2014-09-09 09:29:38 · 4970 阅读 · 0 评论 -
TypeError: 'dict_keys' object does not support indexing
原帖地址:http://stackoverflow.com/questions/17322668/xi-xj-xj-xi-typeerror-dict-keys-object-does-not-support-indexing原创 2014-11-07 08:59:06 · 14837 阅读 · 0 评论 -
python之关键字is和操作符==
Python中所有类型都通过引用存取, 即便是"基本类型"也不例外, 例如:a = 1b = 1 a 和 b 的值都是等于1, 1以对象存储,内存中只有一个1的实例, 可用如下代码判断:id(a) #10249792id(b) #10249792id(a) == id(b) #True 同样也可用关键字 is:a is b #True转载 2014-11-22 10:15:41 · 3470 阅读 · 1 评论 -
Mac 下 PostgreSQL 的安装与使用
在 mac 下,可以利用 homebrew 直接安装 PostgreSQL:1brew installpostgresql -v稍等片刻,PostgreSQL 就安装完成。接下来就是初始数据库,在终端执行一下命令,初始配置 PostgreSQL:1in转载 2014-10-20 09:05:43 · 1494 阅读 · 0 评论 -
在python中排序元组
In Python you can sort with a tuple. It's best illustrated with a simple example:>>> items = [(1, 'B'), (1, 'A'), (2, 'A'), (0, 'B'), (0, 'a')]>>> sorted(items)[(0, 'B'), (0, 'a'), (1, 'A'), (1,翻译 2014-11-04 09:48:29 · 16158 阅读 · 0 评论 -
python3.x: No module named 'urllib2'
在python3.3里面,用urllib.request代替urllib2imurllib.requestresp=urllib.request.urlopen('http://www.baidu.com')html=resp.read()print(html)原创 2014-11-20 21:57:59 · 15457 阅读 · 0 评论 -
Python之lambda
Python 支持一种有趣的语法,它允许你快速定义单行的最小函数。这些叫做 lambda 的函数,是从 Lisp 借用来的,可以用在任何需要函数的地方。例 4.20. lambda 函数介绍>>> def f(x):... return x*2... >>> f(3)6>>> g = lambda x: x*2 >>> g(3)6>>> (原创 2014-11-04 10:04:32 · 560 阅读 · 0 评论 -
python之列表推导式
转自:http://blog.chinaunix.net/uid-28631822-id-3488324.htmlPython语言以简易明了著称,但初次学习Python,却被很多语法搞的昏头涨脑。List comprehension绝对是其中之一。一、困惑 问题一:列表推导式中的变量,是全局变量?还是局部变量?还是闭包变量? 注:一个简单的列转载 2014-11-17 10:00:23 · 3563 阅读 · 1 评论 -
Python TypeError: return arrays must be of ArrayType
当在python中使用原创 2014-11-08 19:05:47 · 16259 阅读 · 0 评论 -
Python 2.x 与 Python3.x 主要区别对照表
Python2.4+ 与 Python3.0+ 主要变化或新增内容Python2 Python3print是内置命令 print变为函数print >> f,x,y print(x,y,file=f)print x, print(x,end='')reload(M)转载 2014-09-16 20:12:52 · 973 阅读 · 0 评论 -
Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
原帖地址:http://blog.youkuaiyun.com/chuanchuan608/article/details/17915959目前正在学习python,使用的工具为python3.2.3。发现3x版本和2x版本有些差异,在套接字编程时,困扰了我很久,先将python核心编程书中的例子代码如下:服务器端:[python] view pla转载 2014-12-01 09:46:17 · 907 阅读 · 0 评论