All posts tagged Python

Python NameError: name ‘readline’ is not defined

Python 2.6.×已经装了有一定时日了,已经完全不知道python的世界都更新到什么境界了;标题这个issue在我更新到Lion之前就已经存在了,所以这不能算是Lion里才introduce的issue,这个还是得有一句说一句;

之前我在Snow Leopard一直没有找到fix的办法,当然主要的原因还在于我也没有那么急切的想fix它,至少对于一个几个月都基本不碰python的家伙而言,它的急迫性显然没有解决starcraft2破解版一联机就自动更新不能玩这个issue来的高,xd:)

BTW, 我只玩战役模式,Blizzard及其各路partner已经完全将starcraft2的对战模式变成网游,虽然我很想支持暴雪买正版,但是网游的各种消耗对我来说是无法容忍的.

貌似又有跑题的趋势…… anyway……

这个issue就是下面这样的,注意倒数第二行:

~ ➔ python
Python 2.6.6 (r266:84292, Sep 13 2010, 20:53:06)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Module readline not available.
Traceback (most recent call last):
  File "/Users/samson/.pythonrc", line 22, in <module>
    readline.read_history_file(historyPath)
NameError: name 'readline' is not defined
>>>

Continue reading →

ruby’s “python -m SimpleHTTPServer”

If I remembered right, the command below used to be the most voted one on commandlinefu.com:

$ python -m SimpleHTTPServer

the “SimpleHTTPServer” module is written in python and it maybe called “the python way”, but that’s not our topic today. what we really want to do here is just making a ruby equivalent for this popular command, using rack.

first, make sure you have rack gem installed on your system (if you’ve installed rails 2.x before, you may already have it):

$ sudo gem install rack

confirm installation (Rack 1.0 should also work for our example):

$ rackup --version
Rack 1.1

alright, preparation is done, let’s start cooking. only a rackup file will be sufficient, for consistency, let’s just call it simple_http_server.ru .

#!/usr/bin/env rackup
#\ -E deployment

use Rack::ContentLength

app = Rack::Directory.new Dir.pwd
run app

Continue reading →

Python 2.x or 3.0

嗯,这是个问题……

A Byte of Python看到的评论是:

If you’re wondering whether to learn Python 2.x or 3.x, then read this article by James Bennett.

貌似是从语言本身支持string Unicode,然后重组一些standard library啥的(最近老是听到restructuration一词,IT裁人不叫lay off,叫restructuration……我就短短时间内已经被restructure了两次了……),不管了,反正我也不知道2.x啥样,不compatible就不compatible:)

准备学习Python和PHP

两种语言之前都接触过,但都没怎么详细了解过,估计都停留在知道长啥样,主要有啥用的level(我很搓的,大家bs我好了:))

在这一并列出,一来是防止自己偷懒借口忘了啥的,要知道我可是经常这样的:);二来是寻求大家的帮助和推荐,看看有啥好的建议和指导否,我知道各位很多都是这方面的高手,所以能得到高手指导,避免走弯路就是最好不过了:)

开始动Python的念头是因为一部日剧《Bloody Monday》的影响,当时好像是在百合Linux/Unix版看到有人发帖说从varvar的blog看到的推荐,我兴冲冲地还自己跑到varvar的blog去confirm了一下,这才决定也去看看,呵呵。

当然这个只是原因之一,另外一个相当重要也是在您看来会比较靠谱的原因是因为Google(还有更靠谱的吗?)。Google内部使用Python估计也已经不是啥新鲜事了,据说Goolge内部能用Python搞定的就不会考虑用别的,整出一个app engine目前也只支持Python,这点是我学习Python的直接导火索,谁叫别人免费呢,有种你Amazon也免费试试,说不定我就不考虑Python了:)
Continue reading →