(裏)世界一言語トークス by Python
-
Upload
yoshiori-shoji -
Category
Documents
-
view
1.427 -
download
1
Transcript of (裏)世界一言語トークス by Python
![Page 1: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/1.jpg)
世界一言語トークスby PythonYoshiori SHOJI
2009年12月14日月曜日
![Page 2: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/2.jpg)
世界一言語トークスby PythonYoshiori SHOJI
裏
2009年12月14日月曜日
![Page 3: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/3.jpg)
注意このプレゼンに登場する
考え方は大変 Python 的ではありません。
ご注意ください。
2009年12月14日月曜日
![Page 4: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/4.jpg)
2009年12月14日月曜日
![Page 5: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/5.jpg)
自 己紹 介
2009年12月14日月曜日
![Page 6: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/6.jpg)
庄司嘉
織2009年12月14日月曜日
![Page 7: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/7.jpg)
庄司嘉
織2009年12月14日月曜日
![Page 8: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/8.jpg)
vaJ a第 一 言 語
2009年12月14日月曜日
![Page 9: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/9.jpg)
vaJ a第 一 言 語
2009年12月14日月曜日
![Page 10: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/10.jpg)
u assa kar b
.
2009年12月14日月曜日
![Page 11: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/11.jpg)
u assa kar b
.
2009年12月14日月曜日
![Page 12: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/12.jpg)
2009年12月14日月曜日
![Page 13: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/13.jpg)
インデントがブロックってキモイ!!
2009年12月14日月曜日
![Page 14: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/14.jpg)
確かにPython はインデントを用いたブロック構造なので
def hoge(): print 'foo' print 'bar'
2009年12月14日月曜日
![Page 15: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/15.jpg)
確かにPython はインデントを用いたブロック構造なので
def hoge(): print 'foo' print 'bar'
def hoge(): print 'foo' print 'bar'
2009年12月14日月曜日
![Page 16: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/16.jpg)
確かにPython はインデントを用いたブロック構造なので
def hoge(): print 'foo' print 'bar'
def hoge(): print 'foo' print 'bar'X2009年12月14日月曜日
![Page 17: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/17.jpg)
でも!!
2009年12月14日月曜日
![Page 18: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/18.jpg)
λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ λ
lambda があるじゃないか!!
2009年12月14日月曜日
![Page 19: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/19.jpg)
でも!?
2009年12月14日月曜日
![Page 20: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/20.jpg)
2009年12月14日月曜日
![Page 21: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/21.jpg)
「文」な困ったちゃん
2009年12月14日月曜日
![Page 22: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/22.jpg)
「文」な困ったちゃん• Python では代入が文•ちょw (再)代入出来ないwwまぁ、関数型っぽくて良いか
2009年12月14日月曜日
![Page 23: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/23.jpg)
「文」な困ったちゃん• Python では代入が文•ちょw (再)代入出来ないwwまぁ、関数型っぽくて良いか
• print が文•ちょw デバッグ出来ねぇwwww
2009年12月14日月曜日
![Page 24: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/24.jpg)
というか
•処理が続けて書けないw• foo() bar() って文じゃんwwww
2009年12月14日月曜日
![Page 25: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/25.jpg)
2009年12月14日月曜日
![Page 26: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/26.jpg)
比較式• if 文とかで使うアレif( A && B ) とか if A and B
• A and B (&&)A を評価して真だったら B を評価
• A or B ( || )A を評価して偽だったら B を評価
2009年12月14日月曜日
![Page 27: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/27.jpg)
irb(main):014:0> p 1 && 2 2=> nilirb(main):015:0> p 1 || 2 1=> nil
比較式
>>> print 1 and 22>>> print 1 or 21
2009年12月14日月曜日
![Page 28: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/28.jpg)
irb(main):014:0> p 1 && 2 2=> nilirb(main):015:0> p 1 || 2 1=> nil
比較式
>>> print 1 and 22>>> print 1 or 21
これじゃね?
2009年12月14日月曜日
![Page 29: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/29.jpg)
Python の真偽値Python では None、 False、ゼロ(数値)、 空配列、空辞書、
及びユーザ定義クラスで __nonzero__() や __len__() が
数値 zero または False を返す場合は偽として扱われます。
それ以外は真として扱われます。
2009年12月14日月曜日
![Page 30: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/30.jpg)
複数の処理を式に
2009年12月14日月曜日
![Page 31: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/31.jpg)
foo() and bar()複数の処理を式に
2009年12月14日月曜日
![Page 32: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/32.jpg)
foo() and bar()左辺が"真"だと右辺が実行される
式になった!!
複数の処理を式に
2009年12月14日月曜日
![Page 33: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/33.jpg)
foo() and bar()左辺が"真"だと右辺が実行される
式になった!!でも
左辺の評価結果が常に"真"にならないと困る
複数の処理を式に
2009年12月14日月曜日
![Page 34: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/34.jpg)
foo() and bar()左辺が"真"だと右辺が実行される
式になった!!でも
左辺の評価結果が常に"真"にならないと困る
[ foo() ] and bar()
複数の処理を式に
2009年12月14日月曜日
![Page 35: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/35.jpg)
foo() and bar()左辺が"真"だと右辺が実行される
式になった!!でも
左辺の評価結果が常に"真"にならないと困る
[ foo() ] and bar()[ ] で囲む事によって要素数 1 のリストになり
常に"真"になる
複数の処理を式に
2009年12月14日月曜日
![Page 36: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/36.jpg)
さらに
2009年12月14日月曜日
![Page 37: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/37.jpg)
[ foo() ] and bar()
さらに
2009年12月14日月曜日
![Page 38: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/38.jpg)
[ foo() ] and bar()
ただの連続処理なら一気に初期化しちゃえばいい
さらに
2009年12月14日月曜日
![Page 39: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/39.jpg)
[foo(), bar(), hoge(),]
[ foo() ] and bar()
ただの連続処理なら一気に初期化しちゃえばいい
さらに
2009年12月14日月曜日
![Page 40: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/40.jpg)
if 文を式にif A : foo() bar()
2009年12月14日月曜日
![Page 41: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/41.jpg)
[ foo() ] and [ bar() ] if A else True
if 文を式にif A : foo() bar()
2009年12月14日月曜日
![Page 42: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/42.jpg)
[ foo() ] and [ bar() ] if A else True2.5から三項演算子が出来たのでそれを使う
if 文を式にif A : foo() bar()
2009年12月14日月曜日
![Page 43: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/43.jpg)
if 文を式に(2)
2009年12月14日月曜日
![Page 44: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/44.jpg)
if 文を式に(2)[[ foo() ] and [ bar() ] if A else True ]
2009年12月14日月曜日
![Page 45: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/45.jpg)
if 文を式に(2)[[ foo() ] and [ bar() ] if A else True ]
これ自体も[ ] で囲む事によって常に"真"になる
2009年12月14日月曜日
![Page 46: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/46.jpg)
[A and [ foo() ] and [ bar() ]]
2.5以前は三項演算子が無かったので
if 文を式に(2)[[ foo() ] and [ bar() ] if A else True ]
これ自体も[ ] で囲む事によって常に"真"になる
2009年12月14日月曜日
![Page 47: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/47.jpg)
for文を式に
2009年12月14日月曜日
![Page 48: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/48.jpg)
Python にはリスト内包表記が有る!!
for文を式に
2009年12月14日月曜日
![Page 49: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/49.jpg)
Python にはリスト内包表記が有る!!
for文を式に
for x in range(10) : foo( x )
2009年12月14日月曜日
![Page 50: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/50.jpg)
Python にはリスト内包表記が有る!!
for文を式に
for x in range(10) : foo( x )
[ foo( x ) for x in range(10) ]
2009年12月14日月曜日
![Page 51: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/51.jpg)
関数の返り値
2009年12月14日月曜日
![Page 52: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/52.jpg)
def hoge( data ): return [foo()] and bar( data )
関数の返り値
2009年12月14日月曜日
![Page 53: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/53.jpg)
def hoge( data ): return [foo()] and bar( data )最初に return 書けば最後に評価した値が返る
関数の返り値
2009年12月14日月曜日
![Page 54: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/54.jpg)
def hoge( data ): return [foo()] and bar( data )最初に return 書けば最後に評価した値が返る
関数の返り値
lambda 化hoge = lambda data :([foo()] and bar( data ) )
2009年12月14日月曜日
![Page 55: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/55.jpg)
tipsprint 文は
代入はリストの append や辞書の__setitem__を使用する。グローバルな名前空間globals()、ローカルの名前空間locals()、そしてオブジェクトxの名前空間x.__dict__
2009年12月14日月曜日
![Page 56: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/56.jpg)
tipsimport sys;[sys.stdout.write(data)]print 文は
代入はリストの append や辞書の__setitem__を使用する。グローバルな名前空間globals()、ローカルの名前空間locals()、そしてオブジェクトxの名前空間x.__dict__
globals().__setitem__("setitem", globals().__setitem__)
2009年12月14日月曜日
![Page 57: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/57.jpg)
2009年12月14日月曜日
![Page 58: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/58.jpg)
で
2009年12月14日月曜日
![Page 59: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/59.jpg)
実際にやってみた(某美人時計の画像ぶっこぬき編)
import sys,os,urllib,time;[[[globals().__setitem__('url','http://www.bijint.com/jp/img/photo/%02d%02d.jpg' % (i, j))] and [globals().__setitem__('file',open(os.path.basename(url), 'wb'))] and [file.write(urllib.urlopen(url).read())] and [file.close()] and [time.sleep(5)] for j in range(60)] for i in range(24)]
2009年12月14日月曜日
![Page 60: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/60.jpg)
実際にやってみた(fizbuzネタ編)
import sys;[globals().__setitem__("setitem", globals().__setitem__)] and [setitem('isSun',lambda : sys.platform.find('java') > -1)] and [setitem('p',lambda data :(isSun() and ([globals().__setitem__('java',__import__('java'))] and [java.lang.System.out.write(java.lang.String(data).getBytes("utf-8"))] and [sys.stdout.write('\n')]) or [sys.stdout.write(data + '\n')]))] and [setitem('fizbuz',lambda i :([setitem('fiz','Fiz')] and [setitem('buz','Buz')] and [setitem('ret','')] and [isSun() and ([setitem('fiz','ふぃずぅ')] and [setitem('buz','ばずぅ')])] and [i % 3 == 0 and setitem('ret', globals().get('ret') + fiz)] and [i % 5 == 0 and setitem('ret', globals().get('ret') + buz)] and [len(globals().get('ret')) == 0 and setitem('ret', str(i))] and ret))] and [p(fizbuz(i)) for i in xrange(20)]
2009年12月14日月曜日
![Page 61: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/61.jpg)
全部式だからPythonなのに
フリーレイアウト!!
2009年12月14日月曜日
![Page 62: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/62.jpg)
インデントがブロックってキモイ!!
2009年12月14日月曜日
![Page 63: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/63.jpg)
インデントがブロックってキモイ!!
別にインデント使わないで書けばいじゃん
2009年12月14日月曜日
![Page 64: (裏)世界一言語トークス by Python](https://reader030.fdocuments.net/reader030/viewer/2022020123/55a05f1f1a28ab4b2e8b467f/html5/thumbnails/64.jpg)
ご清聴ありがとうございました
2009年12月14日月曜日