すぐ忘れるのでメモ
■ 簡単にJsonデコード
>>> json = """{"hoge" : 1, "fuga" : [1, 2, 3]}""" >>> json '{"hoge" : 1, "fuga" : [1, 2, 3]}' >>> eval(json) {'fuga': [1, 2, 3], 'hoge': 1} >>> eval(json)["fuga"] [1, 2, 3]
dictionaryと同じ形式なのでevalするだけでOK.もちろん完全互換じゃないけど.
■ 1要素のタプル
>>> (1,2,3) (1, 2, 3) >>> (1,2) (1, 2) >>> (1) ;; これはNG 1 >>> (1,) ;; これはOK (1,) >>> len((1)) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: object of type 'int' has no len() >>> len((1,)) 1
■ 多次元配列(リスト)
n x mの配列
A = [[0 for j in range(m)] for i in range(n)]
■ meadowのshell-modeでインタプリタ起動
python -i■ 環境変数取得
import os os.environ['HOME']
とか
Referrer
0.950 sec
- 1: http://www.google.co.jp/search?hl=ja&rlz=1B3GGGL_enUS249US249&q=shell+meadow+python+%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%BC%E3%83%97%E3%83%AA%E3%82%BF&start=10&sa=N
- 1: http://search.yahoo.co.jp/search?p=Cshell+Programming+%E9%85%8D%E5%88%97&search.x=1&fr=top_ga1&tid=top_ga1&ei=UTF-8

