ãã¼ãã§ã¯ãPythonãèªãã
ãã¼ãã§ã¯ãPython (PERFECT SERIES 5)
- ä½è : Pythonãµãã¼ã¿ã¼ãº
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/03/05
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 1人 ã¯ãªãã¯: 47å
- ãã®ååãå«ãããã° (2件) ãè¦ã
1åã§è¨èªä»æ§ããææ°ã®æè¡ã¾ã§ãç¶²ç¾ ããå 容ãç¶²ç¾ çã«è§£èª¬ããã¦ããã ãã§ãªããåæè¡ã«é¢ãã¦ã¯åºæ¬ãããã£ãã解説ããå¿ è¦ãªç®æã§ã¯ãæè¡ã®é²æ©ã«ãã£ã¦ãã©ãã¯ããã¯ã¹åãé²ãã ãå é¨å¦çãè£ã§ä½ããã¦ããã®ããæãä¸ãã¦è§£èª¬ãã¦ãããããä½ç³»çã«ç¥ãããåå¿è ã¯ãã¡ããä¸ç´è ã«ããå§ãã®ä¸åã§ã.ææ°ã®Python3.3ã«å¯¾å¿
Python 3ç³»ãæèãã¦ããã¨ããè¨èªä»æ§ãå¨è¾ºã©ã¤ãã©ãªã®ç´¹ä»ã£ã¦ã®ããããã©ããªã«ãã Pythonic ãªæåã§ããã¨ãç¿æ £ã§ããã¨ãããããããZen of Pythonããæ¥æ¬èªã§ããã¾ã§èªããã¦ãããã¨ãè²´éãªæ¸ç±ã ã¨æããã
以ä¸ã¯ç´°ã ã¨ããã¡ã¢ãæ¸ãèµ·ããã¦ã¿ããã ãã¶é ãå¼±ãæããããæç« ã«ãªã£ã¦ããã©ãã¾ããã¯ãã
with 㨠context manager ã«ã¤ãã¦
with open() as f ã£ã¦ããã®ã¯ãã¯ãã¤ãã£ãªã ã«ãªã£ã¦ããã ãã©ããã¨ãã° fabric ã§ã® cd ã³ãã³ãã§ã context manager ã使ã£ã¦ãããããå é¨çã«ã¯ __open__ __exit__ ãªã©ãå¼ã¶ãã¨ã§ç¶æ ã管çã§ããã¨ããã®ã¯ãªãã¨ãªã調ã¹ãã¨ãã«ç¥ã£ã¦ããã©ãå°ãæ´çãã¤ããã
mro 㨠superclass
ããã¯ã©ã®è¨èªã§ããã話ã ãããã©ãæè¿ Django ã® class base view ã mixin ãã¾ãã£ã¦ã¦ããããããªãã£ãã®ã§èª¿ã¹ã¦ããããã®ã¨ãã«ã誰ã親ã¯ã©ã¹ãªã®ããããã®é¢æ°ã¯èª°ã®ãã®ãªã®ããã¨ããã®ãæ¢ãã¨ããmro ãå½¹ã«ç«ã¤ã
æååã¨ãã¤ãå
ãã¶ã Python ã触ãã¨ããã§ãåºãããã®ãããã§ãæååã ã¨ããã£ãããã¤ãå㧠UTF-8 ã«ãªã£ã¦ãªã㦠UnicodeDecodeError ã¨ãã¯ãããããæè¿ã 㨠mesasge pack ã®è©±ããã£ããã©ããã«ããã¤ããªãã¨ãæèããã¦ãªãã³ã¼ãã¨ãããã¨ãããã¾ãå®é ascii(ã¨ããã laten-1 ?) ãªæååãæ±ãåã«ã¯ãããã«ä¸èªç±ããªããæåã®æ±ãã«ã¤ãã¦ããã ãã¨ã ãã¶é¢åãªã®ã§*1é¿ãã¦ãã¨ãããããã©ããããæ´çãã¤ããã
Cæ¡å¼µ
ãã¨ãã° PIL ãããã¨ã cPickle ã¨ãã 㨠C ã®æ¡å¼µã使ããã¨ã«ãªãã¨ããã®ã¯ãããã©ããããå ·ä½çã«ã©ããã£ã¦ãã®ããç¥ãã¦ãã¸ã¼ãã¨æã£ãã
nonlocal ã¨ã¯ãã¼ã¸ã£
JS ã ã¨ããããã¯ãã¼ã¸ã£ã Python ã§ããã¨ããnonlocal ã§ä¸çªè¿ãå¤æ°ãæ¢ãã«ããã¨ããã§ã¤ãããã¨ããã®ã¯ã¡ãã£ã¨ãããããã£ãããã ãããã Python ã¨ãã¦ã©ã使ããã®ãã¯ããããããªãããã©ã
proprety ã¢ã¯ã»ã¹
@property ã @property.setter ã¿ãããªè©±ãå Python/Django の property をどう扱えばいいかモヒカンさんに相談した話 - AtAsAtAmAtArA ã¨ããã®ããããã¨ããã¨ããããé¢æ°ã«åãã¦ããã®ãç¡é£ãã§ãç¶æ ãå¤ãã£ã¦ãªãã®ãªãããããã£ã¨æ示ãã¦ãããããããªãã®ãã¨ãã£ãããã¶ã JavaScript ã«ããã¦ã®ããããã£ã£ã¦è©±ã¨ããããã C ã¿ããã«ããããã£ã¢ã¯ã»ã¹ããªãã¨ããèãæ¹ãç¥ããªãã£ãã®ã§*2ããããããæ´çãã¤ããã
以ä¸
ãã¶ãæéææ³çãªã¨ããã ã£ããã¦ã§ãã®ãã¥ã¼ããªã¢ã«ãããã°ããã¨æããæ¬å½ã«å ¬å¼ã®ãã¥ã¼ããªã¢ã«ã¯å å®ãã¦ãã¦ãããã§ã ããã使ããããã«ãªãã¨ã¯æããã§ããããããªãã¦ããããã Python ãæ¬æ ¼çã«ã¤ããããããã Python ãããã³ã¼ãããããã人ã«ããã¨æãããå人çã«ã¯æåãæ £ç¿ãZen of Python ãªã¨ãããããããå½¢ã§ä¼ãã¦ãããã®ã¯ããã¨ãããããèªåã®å ´åãã¾ãã¾ Python ãªä¼ç¤¾ã§ããããç°å¢ã ã£ãããããç¨åº¦ç¥ãããã©ããã£ã¨ããããç°å¢ã§ããã¨ããã¯å°ãªã*3ã
*1:UTF-16ãUTF-7ã§ããã¨ããã§ã¯EUC-JPã§ããã¨ãã®éãããããã¨ãç¥ã£ã¦ã¦ããããã Python çã«å é¨çã«ã©ãã¾ã§ãã£ã¦ãããç¥ãã®ã¯ãã¾ã¯ã ãã
*2:ãããã¸ã㯠C ã軽ãããã£ãã¨ãã Obj-C ã«ã¤ãã¦ãããããã£ãã¨ãå°ãè³å ã§æ´çãã¤ãã
*3:ã¨ã¯ãããèªåãPEP8ã«ã¯å®å ¨ã«ã¯å¾ã£ã¦ãªãã£ããã¯ãããå ·ä½çã«ã¯80æåæãè¿ããPyPiã«ãªã«ããããããã¨ããªãã