公告版位
新版Blog peichengnote

目前分類:python (64)

瀏覽方式: 標題列表 簡短摘要

[python]python vim plugin 與設定
工欲善其事 必先利其器
碎碎念 :: TAGS::Vim进阶索引[7] :: August :: 2007
http://blah.blogsome.com/2007/08/04/vim_tut_tags/#tags_005fsec4
程式碼可以用tag方式: 將vim當作source insight 來使用 | 易春木
http://eeepage.info/tag-vim-source-insight/
Efficient python folding - Fold python code nicely and toggle with one keystroke : vim online
http://www.vim.org/scripts/script.php?script_id=1494
Python and vim: Make your own IDE | tail -f findings.out
http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/

peicheng 發表在 痞客邦 留言(0) 人氣()

之前寫的crawler 十一月的事情了,
昨天想說把它在開啟來跑不料 404發生了。
python urltest3.py
Traceback (most recent call last):
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Exit 1

使用httpfox , tamper data看了也沒啥異狀,
昨天晚上弄到三點多,

peicheng 發表在 痞客邦 留言(0) 人氣()

從24 hr 到 24秒的優化 multi pattern string match

把問題定義成這樣,
我有 9G的URL list 跟 一份 接近 500個 URL pattern brand list
因為amazon的URL有做SEO的優化,所以說 ,他的URL有包含 廠牌名字 我用brand list去過濾出我要的URL
再去爬取資料。

URL 內有100萬 的

1.

peicheng 發表在 痞客邦 留言(0) 人氣()

cfarrell1980/pywumanber - GitHub
https://github.com/cfarrell1980/pywumanber

在裝 pywumanber的時候遇到的問題
(沒錯,就是大名鼎鼎的agrep 方法  Sun Wu 大神 20年前的作品 wu manber的py binding )
Sun Wu, Ph.D.
http://www.cs.ccu.edu.tw/~sw/
吳昇。吾生
http://w2.cs.ccu.edu.tw/Site/sunwu/

peicheng 發表在 痞客邦 留言(0) 人氣()

很多人都知道python的精神叫做pythonic,
如果你在寫python的時候不pythonic的話,那你就沒資格被稱為python programmer了。

之前在看豆瓣網的首席架構師 洪強寧 做的python在豆瓣網的應用的演講
有其到他怎麼篩選他要的工程師,
當你發現你的工程師在寫python寫了超過 半年 一年,
還不使用list comprehension他就會叫你請回吧。

因為在後來你沒辦法使用語言的特性去思考。

文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

在操作 python dict時,
如果是用 dict['key'] 去做取值的動作,
常常會有KeyError情況產生。

可是使用

dict.get('key')


peicheng 發表在 痞客邦 留言(0) 人氣()

TypeError: int() argument must be a string or a number, not 'NoneType'

常常在做操作或有一個問題就是把string轉成int做比較,
可是卻因為某個沒有值的None type讓程式出錯了,
為了避免這個問題,
使用了這一個小技巧。

int(value or 0)
這樣就可以把其他值轉成0
減少程式發生錯誤了。

peicheng 發表在 痞客邦 留言(0) 人氣()

peicheng@PCsNB ~/project/python/book $ python linkedin__analyze_companies.py

/usr/lib/python2.7/site-packages/nltk-2.0b5-py2.6.egg/nltk/sem/__init__.py:24: UserWarning: nltk.sem.relextract and nltk.sem.chat80 modules not loaded (please install sqlite3 library

USE="tcl" emerge sqlite



文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

Installation instructions — pip 1.0.2 documentation
http://www.pip-installer.org/en/latest/installing.html


$ curl -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py
$ python virtualenv.py my_new_env

在 bin下選擇需要的bashrc or cshrc source他

$ source my_new_env/bin/activate

文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

[python]upload photos from picasa to facebook

這件事情,一直蘊釀很久了。
趁這禮拜告報完,抽出半天的時間。
把 從picasa 相簿 的照片,下載下來並讓他自動上傳到facebook的相簿。
因為比較喜歡用兜的方式寫,
分成了兩個部份。
getpicasa.py

upload2facebook.py兩部份。

文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

[python]在 windows 下 讀寫image open jpg

在unix可能code直接寫成


import urllib2
import sys

response=urllib2.urlopen('https://lh6.googleusercontent.com/-NfkO4cwbvyg/ToMlZ0Wn0xI/AAAAAAAAOE0/4HkR3tZ_doI/s640/IMG_6555.jpg')

文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

python 的list是個不可印的結構,

所以如果說

#-*- coding: utf-8 -*-  
import pprint
pp=pprint.PrettyPrinter(indent=4)

wordlist=['中文','輸入']
strz='這是中文輸入法'
文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

python self
Python为什么要self - 征服Python
http://sjolzy.cn/Why-should-self-Python.html
定義類別
http://caterpillar.onlyfun.net/Gossip/Python/Class.html
OGC Gains Comfort: Python 的 self
http://ogc-daily.blogspot.com/2008/10/python-self.html




文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

要知道現在的資料結構是什麼可以使用

type()

peicheng@PCsNB ~/project/python/chinese $ cat readr3.py 
#coding=utf-8

f=open('rec2','r')
lines=f.readlines()

peicheng 發表在 痞客邦 留言(0) 人氣()

Python处理中文的编码问题 | Leric's Blog
http://www.leric.info/post/94.htm

[Python] Python 3 強力中文處理能力 @ 炎龍老師的 Blog - 國立政治大學 BLOG入口站
http://blog.nccu.edu.tw/blog/53560/365
python中读写文件及中文编码处理方法_我的笔记本_百度空间
http://hi.baidu.com/254584511/blog/item/895546fbc7be47116d22ebe1.html

所以從 Unicode的轉 str,要用encode
從 str轉 unicode的,所以要用decode

peicheng 發表在 痞客邦 留言(0) 人氣()

[python]Extracting Text file contents using Python From mail list

前兩天在找切 record 的方法,
意外看到這麼神奇的解法。


Extracting Text file contents using Python
http://mail.python.org/pipermail/python-list/1999-June/618850.html


文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

以前很多人有個廣告說,
想像力就是你的超能力。 

非常確實的事情,
使用程式語言,能不能做什麼事情,
只在於你要不要去做這些事情,
跟你要用什麼方法來達到。

同樣的效果,可能有很多神妙的方式。

文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

建立資料實體(entity)的作法都事先定義資料模型(data model),
然後再以資料模型產生資料物件。
並設定各個欄位資料之後,再呼叫put() 方法儲存資料物件,使之成為GAE上的資料實體。



peicheng 發表在 痞客邦 留言(0) 人氣()


import urlparse
#domain=
print urlparse.urlparse("http://www.google.com/search?q=fish").netloc



example2


文章標籤

peicheng 發表在 痞客邦 留言(0) 人氣()

ImportError: cannot import name urlsplit


peicheng@PCsNB ~/project/python/test $ python urlparse.py
Traceback (most recent call last):
File "urlparse.py", line 1, in
from urlparse import urlsplit
File "/home/peicheng/project/python/test/urlparse.py", line 1, in
from urlparse import urlsplit
ImportError: cannot import name urlsplit

peicheng 發表在 痞客邦 留言(0) 人氣()