公告版位
新版Blog peichengnote

目前分類:python (64)

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

raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
前陣子再寫一個json crawler在測試時跑起來都滿OK的。
就把他加進去cron裏面跑,
結果他一直吐 No JSON object could be decoded。

問題
url透過 urlopen開啟再read()
好像會讓他讀不到內容。
註解掉的是舊的寫法,

文章標籤

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

Python笔记之and or陷阱 - 未知世界 - ITeye技术网站
http://calmness.iteye.com/blog/227020
Python三目运算,and or陷阱_土拨先生_百度空间
http://hi.baidu.com/tuuboo/blog/item/0945d3fc2c4fbe43d6887dbb.html
[python] and or 表达式陷阱一则。 - cpunion - 博客园
http://www.cnblogs.com/cpunion/archive/2005/08/01/204597.html
4.6. The Peculiar Nature of and and or
http://www.diveintopython.net/power_of_introspection/and_or.html


文章標籤

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

PyCon Taiwan 2012: 付款完成

6/9 6/10 抽空到台北去參加 台灣第1的pycon




文章標籤

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

之前有搞一個星座的parse跟氣象的parse,結果如右邊plugin呈現。
一度的把訊息寄到bbs的個人版上去,當作每日一文摘要。

今天剛好看到這個,現成的api service。
秉持著不重複造輪的精神。

修改一下放入每日一跑的crontab 中。
這樣就獲得了每天天氣預報了。

API · zonble/twweather Wiki

文章標籤

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

python
Help on built-in function all in module __builtin__:

all(...)
all(iterable) -> bool

Return True if bool(x) is True for all values x in the iterable.



文章標籤

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

Instagram以10億美元賣給Facebook

如果Instagram在中国-卢松松博客
http://lusongsong.com/reed/456.html
舊文:網際網路小規模的「創辦團隊」如何成功? (Mr. 6)
http://mr6.cc/?p=7368

不要說創辦人現在不會寫程式,
我知道到co founder跟創辦人現在都是很厲害的系統架構師跟程式設計師,
python 跟 djongo魔人~

文章標籤

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

Plurk Open Source - LightCloud - Distributed and persistent key value database
http://opensource.plurk.com/LightCloud/

原來amix的hash ring是兩個偷吃步。

偷吃步的hash ring
LightCloud 使用了look ring與stroge ring。
作兩次映射,這跟double hash 有異曲同工之妙。
不重複造輪使用最快的kvdb(key value database) Tokyo Tyrant,也就是Tokyo Cabinet 加上網路層。
TT會自己做Master to master的備份。

文章標籤

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

[python]flask 遠端test not localhost
在寫flask 的應用程式若是不是再本地端寫的時候,
在預設的狀態下是無法連入的因為他只bind在127.0.0.1

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

文章標籤

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

[python]command line argv 命令列參數

在C裡面常常使用argv來做參數的輸入。
在python中

import sys
print "\n".join(sys.argv)

假設

文章標籤

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

UnicodeEncodeError: 'ascii' codec can't encode characters ordinal not in range(128)

這個情況常常發生你在print一個你取出的變數的時候。
可能的情況,
可能是你 print的變數沒辦法在print時轉乘 str

我遇到的情況是從dict get出一個u''的值
所以使用

print x.get('key').encode('utf-8')

文章標籤

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

pyvideo.org - Scalability at YouTube
http://pyvideo.org/video/632/scalability-at-youtube

pyvideo.org - Python for data lovers: explore it, analyze it, map it
http://pyvideo.org/video/676/python-for-data-lovers-explore-it-analyze-it-m

pyvideo.org - Stop Writing Classes
http://pyvideo.org/video/880/stop-writing-classes

pyvideo.org - Building A Python-Based Search Engine

文章標籤

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

[python]怎麼複製 itertools to list copy itertools
在使用groupby的時候,
發現同一個for內,操作過的itertools就不見了。
本來使用
new=old 的方式複製
才知道原來他是指到同一個id
所以,
使用new=old[:]
把 舊的list內容複製到new
但是上面作法僅限於list操作。

文章標籤

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

PyCon US 2012 at pyvideo.org -
已經上架了
抽點時間來看看大家在玩什麼~

pyvideo.org - PyCon US 2012
http://pyvideo.org/category/17/pycon-us-2012

toread
pyvideo.org - Social Network Analysis with Python
http://pyvideo.org/video/619/social-network-analysis-with-python

文章標籤

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

[python]lambda map


lambda arguments: expression


其實等於下面這個樣式

 


def name(arguments):
return expression



舉個例來說:

文章標籤

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

[python] python sqlite timestamp localtime datetime

因為做一個時間的顯示使用的db是sqlite


g.db.execute('insert into entries (title, text,time) values (?, ?,datetime(CURRENT_TIMESTAMP,"localtime"))',[request.form['title'], request.form['text']])


因為預設是UTC +0
所以轉換成local 的時間。

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

[python]thread queue block put get task_done not work while loop

Bryce Boe » The Python Multiprocessing Queue and Large Objects
http://www.bryceboe.com/2011/01/28/the-python-multiprocessing-queue-and-large-objects/
why the method get() of python Queue is hang on there? - Python
http://bytes.com/topic/python/answers/523394-why-method-get-python-queue-hang-there
python urllib2 抓取网页 如何捕获各种异常呢 - 其他开发语言 / 脚本语言(Perl ,Python)
http://topic.csdn.net/u/20100106/17/d564f484-9d0f-4364-acb1-6500d7c39fe6.html

urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows - Stack Overflow

文章標籤

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

我們常常遇到一個問題是catch exception後,
除了要知道他的錯誤情況以外,
我們想要知道到底是哪一些發出的錯誤。

tb = sys.exc_info()[2]
print tb.tb_lineno



文章標籤

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

很多情況下再套入json 跟javascript的使用url的時候,
都需要別的作處理轉換一下。
類似

http://peicheng.pixnet.net/blog
轉成
http%3A//peicheng.pixnet.net/blog
http%3A%2F%2Fpeicheng.pixnet.net%2Fblog

使用

文章標籤

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

How to sort a Python dict (dictionary) by keys or values « SaltyCrane Blog
http://www.saltycrane.com/blog/2007/09/how-to-sort-python-dictionary-by-keys/



文章標籤

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

[python]word count / word frequency

有一個list
[a,b,c,a,b,b,a]
要成為
{'a':2,'b':3,'c:1'}


from collections import defaultdict
文章標籤

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