è¯ãäžæ¥ã ããã§ãå€ãã®ããããã¹ã¯åžæ°ããã°ãŒã°ã«ã«ããPythonèšèªã®ã¹ã¿ã€ã«ã¬ã€ãã®ç¿»èš³ã®ç¬¬2éšã®åºçã®æãæ¥ãŸããïŒç¬¬1éšã¯æ éã«ä¿åãããŸãïŒã 次ã«ãPythonããã°ã©ãã³ã°èšèªã§ã®ãœãŒã¹ã³ãŒãã®ãã©ãŒãããã«çŽæ¥è§ŠããŸãã ãåç¥ã®ããã«ãæž æœã¯å¥åº·ãžã®éµã§ãããããã°ã©ã ã³ãŒãã®æž æœã¯ååããã®æ¬æãšïŒçæ³çã«ã¯ïŒäžèšã®èª°ãããã®å±ãŸãã®éµã§ãã äžè¬ã«ãPythonèªäœã¯èªã¿ãããèšèªã§ããããã®èšèªã®æ§æã§ãããã³ãŒãå ïŒããã³çµæãšããŠããããå ïŒã«é åºãå¿ èŠãšããŸãã ããããç§ãã¡äžäººäžäººã¯ç§ãã¡èªèº«ã®ããã¥ã¡ã³ã¿ãªãŒã§ãããç§ãã¡èªèº«ã®ãã¶ã€ã³ã®åµé è ã§ãã ãããŠããã§ã«äžåºŠèšãããããã«ãæš©åšããåå¿ã®æèŠã«è³ãåŸããããåŸãŸããã ãã®ãããGoogle Pythonã¹ã¿ã€ã«ã¬ã€ãã®ç¬¬2éš-Pythonã¹ã¿ã€ã«ã«ãŒã«ã¯ãããªããåŸ ã£ãŠããŸãã ãããŠã pdfã¯ããããã«ãããŸãã
Pythonã¹ã¿ã€ã«ã«ãŒã«
ã»ãã³ãã³
è¡ãã»ãã³ãã³ã§åå²ããªãã§ãã ãã
è¡ãã»ãã³ãã³ã§åºåã£ãããã»ãã³ãã³ã䜿çšããŠåãè¡ã«ããã³ãã³ããåºåã£ããããªãã§ãã ããã
è¡ã®é·ã
æ倧è¡é·-80æå
ããã¯ã¹ã©ãã·ã¥ãæ¹è¡ãšããŠäœ¿çšããªãã§ãã ããã æ¬åŒ§ãšäžæ¬åŒ§ã§Pythonã®æ瀺çãªæååé£çµã䜿çšããŸãã å¿ èŠã«å¿ããŠãåŒã®ååŸã«ãã©ã±ããã®äœåãªãã¢ãè¿œå ã§ããŸãã
è¯ãïŒ
ããã¹ãã1è¡ã«åãŸããªãå Žåã¯ãæ¬åŒ§ã䜿çšããŠè¡ãæ瀺çã«é£çµããŸãã
ã³ã¡ã³ãã«ã€ããŠã¯ãå¿ èŠã«å¿ããŠ1è¡ã«é·ãURLãå ¥åããŸãã
è¯ãïŒ
æªãïŒ
äžèšã®è¡ã®èŠçŽ ã®ã€ã³ãã³ãã«æ³šæããŠãã ããïŒè©³çŽ°ã«ã€ããŠã¯ãã€ã³ãã³ãã®ã»ã¯ã·ã§ã³ãåç §ããŠãã ããïŒã
äŸå€
- é·ãã€ã³ããŒãæåå
- ã³ã¡ã³ãå ã®URL
ããã¯ã¹ã©ãã·ã¥ãæ¹è¡ãšããŠäœ¿çšããªãã§ãã ããã æ¬åŒ§ãšäžæ¬åŒ§ã§Pythonã®æ瀺çãªæååé£çµã䜿çšããŸãã å¿ èŠã«å¿ããŠãåŒã®ååŸã«ãã©ã±ããã®äœåãªãã¢ãè¿œå ã§ããŸãã
è¯ãïŒ
foo_bar(self, width, height, color='black', design=None, x='foo', emphasis=None, highlight=0) if (width == 0 and height == 0 and color == 'red' and emphasis == 'strong'):
ããã¹ãã1è¡ã«åãŸããªãå Žåã¯ãæ¬åŒ§ã䜿çšããŠè¡ãæ瀺çã«é£çµããŸãã
x = ('This will build a very long long ' 'long long long long long long string')
ã³ã¡ã³ãã«ã€ããŠã¯ãå¿ èŠã«å¿ããŠ1è¡ã«é·ãURLãå ¥åããŸãã
è¯ãïŒ
# See details at # http://www.example.com/us/developer/documentation/api/content/v2.0/csv_file_name_extension_full_specification.html
æªãïŒ
# See details at # http://www.example.com/us/developer/documentation/api/content/\ # v2.0/csv_file_name_extension_full_specification.html
äžèšã®è¡ã®èŠçŽ ã®ã€ã³ãã³ãã«æ³šæããŠãã ããïŒè©³çŽ°ã«ã€ããŠã¯ãã€ã³ãã³ãã®ã»ã¯ã·ã§ã³ãåç §ããŠãã ããïŒã
ãã©ã±ãã
ãã©ã±ããã¯æ§ããã«äœ¿çšãã
æ¹è¡ãæŽçããããªãå Žåã¯ã returnåŒãæ¡ä»¶ä»ãæ§é ã§ãããïŒãã©ã±ããïŒã䜿çšããªãã§ãã ããã ïŒäžèšãåç
§ïŒã ãã ããã¿ãã«ã®äœæã«ã¯æ¬åŒ§ãé©ããŠããŸãã
è¯ãïŒ
æªãïŒ
è¯ãïŒ
if foo: bar() while x: x = bar() if x and y: bar() if not x: bar() return foo for (x, y) in dict.items(): ...
æªãïŒ
if (x): bar() if not(x): bar() return (foo)
ããŒã¿
ã¿ããŸãã¯ã¿ããšã¹ããŒã¹ã®æ··åç©ã䜿çšããªãã§ãã ãã
è¡ã®æãè¿ããæå³ããå Žåã¯ãè¡ã®é·ãã«é¢ããäŸã§èª¬æãããŠããããã«ãæãè¿ãããåèŠçŽ ãåçŽæ¹åã«æŽåããããã4ã€ã®ã¹ããŒã¹ã®ã€ã³ãã³ãã䜿çšããå¿
èŠããããŸãããã®å Žåãæåã®è¡ã«åäžã®åŒæ°ã¯ãããŸããã
è¯ãïŒ
æªãïŒ
è¯ãïŒ
# Aligned with opening delimiter foo = long_function_name(var_one, var_two, var_three, var_four) # 4-space hanging indent; nothing on first line foo = long_function_name( var_one, var_two, var_three, var_four)
æªãïŒ
# Stuff on first line forbidden foo = long_function_name(var_one, var_two, var_three, var_four) # 2-space hanging indent forbidden foo = long_function_name( var_one, var_two, var_three, var_four)
空è¡
ãããã¬ãã«ã®åºåã®éã«ã¯2è¡ã®ç©ºçœè¡ãå¿
èŠã§ã
æäžäœã®å®£èšã®éã«ã¯2ã€ã®ç©ºè¡ããããã¡ãœãã宣èšã®éã«ã¯1ã€ã®ç©ºè¡ãããã¯ãã§ãã æäžäœã®å®£èšã®éã«ã¯ãã¯ã©ã¹ã§ããé¢æ°ã§ããã2è¡ã®ç©ºçœè¡ãå¿
èŠã§ãã ã¡ãœããã®å®çŸ©ã®éãããã³ã¯ã©ã¹ã®å®£èšãšãã®æåã®ã¡ãœããã®éã«ã¯ã1è¡ã®ç©ºè¡ãå¿
èŠã§ãã é¢æ°ãšã¡ãœããã®å
éšã§ã¯ãå¿
èŠã«å¿ããŠåäžã®ç©ºã®æååã䜿çšããŸãã
ã¹ããŒã¹
å¥èªç¹ã§ã¹ããŒã¹ã䜿çšããå Žåã¯ãæšæºã®å°å·äžã®ã¬ã€ãã©ã€ã³ã«åŸã£ãŠãã ããã
è§ãã£ãå
ã«ã¹ããŒã¹ã¯ãããŸããã
è¯ãïŒ ã¹ãã ïŒãã [1]ã{åµïŒ2}ã[]ïŒ
æªãïŒ ã¹ãã ïŒãã [1]ã{åµïŒ2}ã[]ïŒ
ã»ãã³ãã³ãã»ãã³ãã³ããŸãã¯ããªãªãã®åã«ã¹ããŒã¹ã¯ãããŸããã è¡æ«ã«ããå Žåãé€ããå°æ°ç¹ãã»ãã³ãã³ããŸãã¯ããªãªãã®åŸã«ã¹ããŒã¹ã䜿çšããŸãã
è¯ãïŒ
æªãïŒ
åŒæ°ãªã¹ããã€ã³ããã¯ã¹ããŸãã¯ã¹ã©ã€ã¹ãéå§ããéå§ãã©ã±ããã®åã«ã¹ããŒã¹ã¯ãããŸããã
è¯ãïŒ ã¹ãã ïŒ1ïŒ
æªãïŒ ã¹ãã ïŒ1ïŒ
è¯ãïŒ dict ['key'] =ãªã¹ã[ã€ã³ããã¯ã¹]
æªãïŒ dict ['key'] = list [index]
äž¡åŽã«åäžã®ã¹ããŒã¹ãå«ãäºé æŒç®åãå²ã¿ãããã¯å²ãåœãŠïŒ = ïŒãæ¯èŒæŒç®åïŒ ==ã<ã> ã! =ã<>ã<=ã> =ãInãnot inãisãis not ïŒã«é©çšãããããŒã«æŒç®åïŒandãorãnotïŒã é©åã ãšæããã®ã䜿çšããŠãã ãã
ç®è¡æŒç®åã«é¢ããŠã¯ã¹ããŒã¹ã䜿çšããŸããããã€ããªæŒç®åã®äž¡åŽã«åžžã«ã¹ããŒã¹ãé 眮ãããšãã³ãŒãã®æŽåæ§ã確ä¿ãããŸãã
è¯ãïŒ x == 1
æªãïŒ x <1
ååä»ãåŒæ°ãŸãã¯ããã©ã«ãå€ã瀺ãããã«=èšå·ã䜿çšããå Žåã¯ã=èšå·ã®äž¡åŽã«ã¹ããŒã¹ã䜿çšããªãã§ãã ããã
è¯ãïŒ
æªãïŒ
äœçœ®åããã¯é¢åãªã®ã§ãã¹ããŒã¹ã䜿çšããŠé£ç¶ããè¡ã®éšåãåçŽã«äœçœ®åããããªãã§ãã ããã ïŒé©çšå¯Ÿè±¡ïŒãïŒã=ãªã©ïŒïŒ
è¯ãïŒ
æªãïŒ
è¯ãïŒ ã¹ãã ïŒãã [1]ã{åµïŒ2}ã[]ïŒ
æªãïŒ ã¹ãã ïŒãã [1]ã{åµïŒ2}ã[]ïŒ
ã»ãã³ãã³ãã»ãã³ãã³ããŸãã¯ããªãªãã®åã«ã¹ããŒã¹ã¯ãããŸããã è¡æ«ã«ããå Žåãé€ããå°æ°ç¹ãã»ãã³ãã³ããŸãã¯ããªãªãã®åŸã«ã¹ããŒã¹ã䜿çšããŸãã
è¯ãïŒ
if x == 4: print x, y x, y = y, x
æªãïŒ
if x == 4 : print x , y x , y = y , x
åŒæ°ãªã¹ããã€ã³ããã¯ã¹ããŸãã¯ã¹ã©ã€ã¹ãéå§ããéå§ãã©ã±ããã®åã«ã¹ããŒã¹ã¯ãããŸããã
è¯ãïŒ ã¹ãã ïŒ1ïŒ
æªãïŒ ã¹ãã ïŒ1ïŒ
è¯ãïŒ dict ['key'] =ãªã¹ã[ã€ã³ããã¯ã¹]
æªãïŒ dict ['key'] = list [index]
äž¡åŽã«åäžã®ã¹ããŒã¹ãå«ãäºé æŒç®åãå²ã¿ãããã¯å²ãåœãŠïŒ = ïŒãæ¯èŒæŒç®åïŒ ==ã<ã> ã! =ã<>ã<=ã> =ãInãnot inãisãis not ïŒã«é©çšãããããŒã«æŒç®åïŒandãorãnotïŒã é©åã ãšæããã®ã䜿çšããŠãã ãã
ç®è¡æŒç®åã«é¢ããŠã¯ã¹ããŒã¹ã䜿çšããŸããããã€ããªæŒç®åã®äž¡åŽã«åžžã«ã¹ããŒã¹ãé 眮ãããšãã³ãŒãã®æŽåæ§ã確ä¿ãããŸãã
è¯ãïŒ x == 1
æªãïŒ x <1
ååä»ãåŒæ°ãŸãã¯ããã©ã«ãå€ã瀺ãããã«=èšå·ã䜿çšããå Žåã¯ã=èšå·ã®äž¡åŽã«ã¹ããŒã¹ã䜿çšããªãã§ãã ããã
è¯ãïŒ
def complex(real, imag=0.0): return magic(r=real, i=imag)
æªãïŒ
def complex(real, imag = 0.0): return magic(r = real, i = imag)
äœçœ®åããã¯é¢åãªã®ã§ãã¹ããŒã¹ã䜿çšããŠé£ç¶ããè¡ã®éšåãåçŽã«äœçœ®åããããªãã§ãã ããã ïŒé©çšå¯Ÿè±¡ïŒãïŒã=ãªã©ïŒïŒ
è¯ãïŒ
foo = 1000 # comment long_name = 2 # comment that should not be aligned dictionary = { 'foo': 1, 'long_name': 2, }
æªãïŒ
foo = 1000 # comment long_name = 2 # comment that should not be aligned dictionary = { 'foo' : 1, 'long_name': 2, }
æååïŒïŒ ïŒããã·ã¥ãã³ã°ïŒ
ã»ãšãã©ã®.pyãã¡ã€ã«ã¯ãïŒè¡ã§å®è¡ããå¿
èŠã¯ãããŸããïŒ
ïŒïŒ/ Usr / bin / pythonã䜿çšããŠã¡ã€ã³ããã°ã©ã ãã¡ã€ã«ãå®è¡ããŸãã ãã®è¡ã¯ãã«ãŒãã«ãPythonã€ã³ã¿ãŒããªã¿ãŒãèŠã€ããããã«äœ¿çšãããŸãããã¢ãžã¥ãŒã«ãã€ã³ããŒãããããšãã«Pythonã«ãã£ãŠç¡èŠãããŸãã ããã¯ãçŽæ¥å®è¡ããããã¡ã€ã«ã«å¿
èŠã§ãã
ã³ã¡ã³ã
æ£ããã¹ã¿ã€ã«ã䜿çšããŠãã ããã
ã¢ãžã¥ãŒã«ãé¢æ°ãã¡ãœããããŸãã¯æååã³ã¡ã³ãã«æ£ããã¹ã¿ã€ã«ã䜿çšããŠãã ããã
Pythonã«ã¯ãç¬èªã®ã³ã¡ã³ãã¹ã¿ã€ã«ïŒããã¥ã¡ã³ãè¡ïŒããããŸãã ããã¥ã¡ã³ãè¡ã¯ãããã±ãŒãžãã¢ãžã¥ãŒã«ãã¯ã©ã¹ããŸãã¯é¢æ°ã®æåã®æ§æèŠçŽ ã§ããè¡ã§ãã ãã®ãããªæååã¯__doc__ãªããžã§ã¯ãå±æ§ã䜿çšããŠèªåçã«ãšã¯ã¹ããŒãã§ããpydocã§äœ¿çšãããŸãã ïŒã¢ãžã¥ãŒã«ã§pydocãå®è¡ããŠãã©ã®ããã«èŠãããã確èªããŠãã ãããïŒããã¥ã¡ã³ããŒã·ã§ã³ã©ã€ã³ã¢ã°ãªãŒã¡ã³ãã§ã¯ã3è¡ã®äºéåŒçšç¬Šã䜿çšããŠããã®ãããªè¡ãæ§æããŸãã ããã¥ã¡ã³ããŒã·ã§ã³è¡ã¯ã空è¡ã«ç¶ãæåæ°ãçå笊ãŸãã¯æå笊ã®æ°ãäžèŽãããµããªãŒè¡ïŒ1ã€ã®ç©çè¡ïŒãšããŠç·šæããã«ãŒãœã«äœçœ®ããã®æ®ãã®ããã¥ã¡ã³ããŒã·ã§ã³è¡ãæåã®è¡ã®æåã®åŒçšãšããŠé 眮ããå¿ èŠããããŸãã 以äžã¯ãããã¥ã¡ã³ãè¡ã®èšèšã«é¢ããããã«è©³ããæ å ±ã§ãã
åãã¡ã€ã«ã«ã¯ã©ã€ã»ã³ã¹ãã³ãã¬ãŒããå«ãŸããŠããå¿ èŠããããŸãã ãããžã§ã¯ãã«é©ããã©ã€ã»ã³ã¹ãã³ãã¬ãŒããéžæããŸãïŒããšãã°ãApache 2.0ãBSDãLGPLãGPLïŒã
ãã®ã»ã¯ã·ã§ã³ã§äœ¿çšãããçšèªïŒé¢æ°ïŒã¯ãã¡ãœãããé¢æ°ãããã³ãžã§ãã¬ãŒã¿ãŒãæããŸãã
以äžã«èª¬æããå Žåãé€ããé¢æ°ã«ã¯ãã¹ãŠã®å Žåã«ããã¥ã¡ã³ãè¡ãå¿ èŠã§ãã
ããã¥ã¡ã³ãè¡ã¯ããœãŒã¹ã³ãŒããèªã¿åããã«é¢æ°åŒã³åºããè¡ãã®ã«ååãªæ å ±ãæäŸããå¿ èŠããããŸãã ããã¥ã¡ã³ãè¡ã§ã¯ãé¢æ°åŒã³åºãã®æ§æãšãã®ã»ãã³ãã£ã¯ã¹ã説æããå¿ èŠããããŸããããã®å®è£ ã«ã€ããŠã¯èª¬æããªãã§ãã ããã æ±ãã«ããã³ãŒãã®å ŽåããœãŒã¹ã³ãŒãå ã®ã³ã¡ã³ãã¯ããã¥ã¡ã³ãè¡ãããæãŸããã§ãã é¢æ°ã®ç¹å®ã®åŽé¢ã¯ã以äžã«ãªã¹ããããŠããç¹å¥ãªã»ã¯ã·ã§ã³ã§ææžåãããå¿ èŠããããŸãã åã»ã¯ã·ã§ã³ã¯ããããã§çµããã¿ã€ãã«ããŒã§å§ãŸããŸãã ã»ã¯ã·ã§ã³ã¯ãããããŒãé€ãã2ã€ã®ã¹ããŒã¹ã§ã€ã³ãã³ãããå¿ èŠããããŸãã
åŒæ° ïŒ
åãã©ã¡ãŒã¿ãŒãååã§ãªã¹ãããŸãã 説æã¯ååã®ããåŸã«ç¶ããããããšã¹ããŒã¹ã§åºåãå¿ èŠããããŸãã 説æãé·ãããŠ80æåã«åãŸããªãå Žåã¯ã2ã€ãŸãã¯4ã€ã®ã¹ããŒã¹ã®äžæã€ã³ãã³ãã䜿çšããŸãïŒãã¡ã€ã«å šäœã®ãã¶ã€ã³ã«äžè²«æ§ãæãããïŒã
説æã§ã¯ãåŒæ°ã®å¿ èŠãªã¿ã€ããšç®çãåç §ããå¿ èŠããããŸãã é¢æ°ã* fooïŒå¯å€é·åŒæ°ãªã¹ãïŒããã³/ãŸãã¯** barïŒããŒå€åŒæ°ã®ä»»æã®ã»ããïŒãèš±å¯ããå Žåããããã¯* fooããã³** barãšããŠèšè¿°ãããå¿ èŠããããŸãã
æ»ãå€ ïŒïŒãŸãã¯ãžã§ãã¬ãŒã¿ãŒã®ã€ãŒã«ã ïŒ
æ»ãå€ã®ã¿ã€ããšã»ãã³ãã£ã¯ã¹ã説æããŸãã é¢æ°ãåžžã«Noneãè¿ãå Žåããã®ã»ã¯ã·ã§ã³ã¯ãªãã·ã§ã³ã§ãã
çºç ïŒ
ãã®ã€ã³ã¿ãŒãã§ãŒã¹ã§å¯èœãªãã¹ãŠã®äŸå€ã®ãªã¹ãã
ã¯ã©ã¹ã«ã¯ã宣èšã®äžã«ããã¥ã¡ã³ãè¡ãå¿ èŠã§ãã ã¯ã©ã¹ã«ãããªãã¯å±æ§ãããå Žåãå±æ§ã»ã¯ã·ã§ã³ã«ããã«ææžåããåŒæ°ã»ã¯ã·ã§ã³ãšåãæžåŒã¹ã¿ã€ã«ã«åŸãå¿ èŠããããŸãã
ã³ã¡ã³ãã®æåŸã®å Žæã¯ãã³ãŒãå ã®æ±ãã«ããå Žæã§ãã 次åã®ã³ãŒãã¬ãã¥ãŒã§ããããæ確ã«ããå Žåã¯ãããã§ã³ã¡ã³ãããå¿ èŠããããŸãã å®è¡ããåã«æ°è¡ã®ããã¥ã¡ã³ããååŸããè€éãªæäœã æé»ã®éšåã«ã¯ãè¡æ«ã«ã³ã¡ã³ããå¿ èŠã§ãã
èªã¿ãããããããã«ããã®ãããªã³ã¡ã³ãã¯ã³ãŒãããå°ãªããšã2ã¹ããŒã¹å¿ èŠã§ãã äžæ¹ãã³ãŒãããŸã£ããèšè¿°ããªãæ¹ãè¯ãã§ãããã ãã®ã³ãŒããèªãã§ãã人ã¯ãããªããããPythonïŒããªããããããšããããšã§ã¯ãªãïŒãããç¥ã£ãŠãããšä»®å®ããŸãã
ããã¥ã¡ã³ãè¡ã
Pythonã«ã¯ãç¬èªã®ã³ã¡ã³ãã¹ã¿ã€ã«ïŒããã¥ã¡ã³ãè¡ïŒããããŸãã ããã¥ã¡ã³ãè¡ã¯ãããã±ãŒãžãã¢ãžã¥ãŒã«ãã¯ã©ã¹ããŸãã¯é¢æ°ã®æåã®æ§æèŠçŽ ã§ããè¡ã§ãã ãã®ãããªæååã¯__doc__ãªããžã§ã¯ãå±æ§ã䜿çšããŠèªåçã«ãšã¯ã¹ããŒãã§ããpydocã§äœ¿çšãããŸãã ïŒã¢ãžã¥ãŒã«ã§pydocãå®è¡ããŠãã©ã®ããã«èŠãããã確èªããŠãã ãããïŒããã¥ã¡ã³ããŒã·ã§ã³ã©ã€ã³ã¢ã°ãªãŒã¡ã³ãã§ã¯ã3è¡ã®äºéåŒçšç¬Šã䜿çšããŠããã®ãããªè¡ãæ§æããŸãã ããã¥ã¡ã³ããŒã·ã§ã³è¡ã¯ã空è¡ã«ç¶ãæåæ°ãçå笊ãŸãã¯æå笊ã®æ°ãäžèŽãããµããªãŒè¡ïŒ1ã€ã®ç©çè¡ïŒãšããŠç·šæããã«ãŒãœã«äœçœ®ããã®æ®ãã®ããã¥ã¡ã³ããŒã·ã§ã³è¡ãæåã®è¡ã®æåã®åŒçšãšããŠé 眮ããå¿ èŠããããŸãã 以äžã¯ãããã¥ã¡ã³ãè¡ã®èšèšã«é¢ããããã«è©³ããæ å ±ã§ãã
ã¢ãžã¥ãŒã«
åãã¡ã€ã«ã«ã¯ã©ã€ã»ã³ã¹ãã³ãã¬ãŒããå«ãŸããŠããå¿ èŠããããŸãã ãããžã§ã¯ãã«é©ããã©ã€ã»ã³ã¹ãã³ãã¬ãŒããéžæããŸãïŒããšãã°ãApache 2.0ãBSDãLGPLãGPLïŒã
é¢æ°ãšã¡ãœãã
ãã®ã»ã¯ã·ã§ã³ã§äœ¿çšãããçšèªïŒé¢æ°ïŒã¯ãã¡ãœãããé¢æ°ãããã³ãžã§ãã¬ãŒã¿ãŒãæããŸãã
以äžã«èª¬æããå Žåãé€ããé¢æ°ã«ã¯ãã¹ãŠã®å Žåã«ããã¥ã¡ã³ãè¡ãå¿ èŠã§ãã
- ã¢ãžã¥ãŒã«ã®å€åŽããã¯èŠããŸãã
- ãšãŠãçã
- æããïŒèªã¿ãããïŒ
ããã¥ã¡ã³ãè¡ã¯ããœãŒã¹ã³ãŒããèªã¿åããã«é¢æ°åŒã³åºããè¡ãã®ã«ååãªæ å ±ãæäŸããå¿ èŠããããŸãã ããã¥ã¡ã³ãè¡ã§ã¯ãé¢æ°åŒã³åºãã®æ§æãšãã®ã»ãã³ãã£ã¯ã¹ã説æããå¿ èŠããããŸããããã®å®è£ ã«ã€ããŠã¯èª¬æããªãã§ãã ããã æ±ãã«ããã³ãŒãã®å ŽåããœãŒã¹ã³ãŒãå ã®ã³ã¡ã³ãã¯ããã¥ã¡ã³ãè¡ãããæãŸããã§ãã é¢æ°ã®ç¹å®ã®åŽé¢ã¯ã以äžã«ãªã¹ããããŠããç¹å¥ãªã»ã¯ã·ã§ã³ã§ææžåãããå¿ èŠããããŸãã åã»ã¯ã·ã§ã³ã¯ããããã§çµããã¿ã€ãã«ããŒã§å§ãŸããŸãã ã»ã¯ã·ã§ã³ã¯ãããããŒãé€ãã2ã€ã®ã¹ããŒã¹ã§ã€ã³ãã³ãããå¿ èŠããããŸãã
åŒæ° ïŒ
åãã©ã¡ãŒã¿ãŒãååã§ãªã¹ãããŸãã 説æã¯ååã®ããåŸã«ç¶ããããããšã¹ããŒã¹ã§åºåãå¿ èŠããããŸãã 説æãé·ãããŠ80æåã«åãŸããªãå Žåã¯ã2ã€ãŸãã¯4ã€ã®ã¹ããŒã¹ã®äžæã€ã³ãã³ãã䜿çšããŸãïŒãã¡ã€ã«å šäœã®ãã¶ã€ã³ã«äžè²«æ§ãæãããïŒã
説æã§ã¯ãåŒæ°ã®å¿ èŠãªã¿ã€ããšç®çãåç §ããå¿ èŠããããŸãã é¢æ°ã* fooïŒå¯å€é·åŒæ°ãªã¹ãïŒããã³/ãŸãã¯** barïŒããŒå€åŒæ°ã®ä»»æã®ã»ããïŒãèš±å¯ããå Žåããããã¯* fooããã³** barãšããŠèšè¿°ãããå¿ èŠããããŸãã
æ»ãå€ ïŒïŒãŸãã¯ãžã§ãã¬ãŒã¿ãŒã®ã€ãŒã«ã ïŒ
æ»ãå€ã®ã¿ã€ããšã»ãã³ãã£ã¯ã¹ã説æããŸãã é¢æ°ãåžžã«Noneãè¿ãå Žåããã®ã»ã¯ã·ã§ã³ã¯ãªãã·ã§ã³ã§ãã
çºç ïŒ
ãã®ã€ã³ã¿ãŒãã§ãŒã¹ã§å¯èœãªãã¹ãŠã®äŸå€ã®ãªã¹ãã
def fetch_bigtable_rows(big_table, keys, other_silly_variable=None): """Fetches rows from a Bigtable. Retrieves rows pertaining to the given keys from the Table instance represented by big_table. Silly things may happen if other_silly_variable is not None. Args: big_table: An open Bigtable Table instance. keys: A sequence of strings representing the key of each table row to fetch. other_silly_variable: Another optional variable, that has a much longer name than the other args, and which does nothing. Returns: A dict mapping keys to the corresponding table row data fetched. Each row is represented as a tuple of strings. For example: {'Serak': ('Rigel VII', 'Preparer'), 'Zim': ('Irk', 'Invader'), 'Lrrr': ('Omicron Persei 8', 'Emperor')} If a key from the keys argument is missing from the dictionary, then that row was not found in the table. Raises: IOError: An error occurred accessing the bigtable.Table object. """ pass
ã¯ã©ã¹
ã¯ã©ã¹ã«ã¯ã宣èšã®äžã«ããã¥ã¡ã³ãè¡ãå¿ èŠã§ãã ã¯ã©ã¹ã«ãããªãã¯å±æ§ãããå Žåãå±æ§ã»ã¯ã·ã§ã³ã«ããã«ææžåããåŒæ°ã»ã¯ã·ã§ã³ãšåãæžåŒã¹ã¿ã€ã«ã«åŸãå¿ èŠããããŸãã
class SampleClass(object): """Summary of class here. Longer class information.... Longer class information.... Attributes: likes_spam: A boolean indicating if we like SPAM or not. eggs: An integer count of the eggs we have laid. """ def __init__(self, likes_spam=False): """Inits SampleClass with blah.""" self.likes_spam = likes_spam self.eggs = 0 def public_method(self): """Performs operation blah."""
ãããã¯ãšã€ã³ã©ã€ã³ã³ã¡ã³ã
ã³ã¡ã³ãã®æåŸã®å Žæã¯ãã³ãŒãå ã®æ±ãã«ããå Žæã§ãã 次åã®ã³ãŒãã¬ãã¥ãŒã§ããããæ確ã«ããå Žåã¯ãããã§ã³ã¡ã³ãããå¿ èŠããããŸãã å®è¡ããåã«æ°è¡ã®ããã¥ã¡ã³ããååŸããè€éãªæäœã æé»ã®éšåã«ã¯ãè¡æ«ã«ã³ã¡ã³ããå¿ èŠã§ãã
# We use a weighted dictionary search to find out where i is in # the array. We extrapolate position based on the largest num # in the array and the array size and then do binary search to # get the exact number. if i & (i-1) == 0: # true iff i is a power of 2
èªã¿ãããããããã«ããã®ãããªã³ã¡ã³ãã¯ã³ãŒãããå°ãªããšã2ã¹ããŒã¹å¿ èŠã§ãã äžæ¹ãã³ãŒãããŸã£ããèšè¿°ããªãæ¹ãè¯ãã§ãããã ãã®ã³ãŒããèªãã§ãã人ã¯ãããªããããPythonïŒããªããããããšããããšã§ã¯ãªãïŒãããç¥ã£ãŠãããšä»®å®ããŸãã
# BAD COMMENT: Now go through the b array and make sure whenever i occurs # the next element is i+1
ã¯ã©ã¹
ã¯ã©ã¹ãã©ã®ã¯ã©ã¹ãããç¶æ¿ããªãå Žåã¯ãã¯ã©ã¹ãªããžã§ã¯ãããæ瀺çã«ç¶æ¿ããŸã
ããã¯ããã¹ããããã¯ã©ã¹ã«ãé©çšãããŸãã
è¯ãïŒ
æªãïŒ
ããããã£ãæ£ããæ©èœãããã«ã¯ããªããžã§ã¯ãã¯ã©ã¹ããç¶æ¿ããå¿ èŠããããPython 3000ãšã®éäºææ§ããã³ãŒããä¿è·ããŸãããŸãããªããžã§ã¯ãã®æšæºçãªã»ãã³ãã£ã¯ã¹ãå®è£ ããç¹å¥ãªã¡ãœãããå®çŸ©ããŸãã ã__ repr__ãããã³__str__ ã
è¯ãïŒ
class SampleClass(object): pass class OuterClass(object): class InnerClass(object): pass class ChildClass(ParentClass): """Explicitly inherits from another class already."""
æªãïŒ
class SampleClass: pass class OuterClass: class InnerClass: pass
ããããã£ãæ£ããæ©èœãããã«ã¯ããªããžã§ã¯ãã¯ã©ã¹ããç¶æ¿ããå¿ èŠããããPython 3000ãšã®éäºææ§ããã³ãŒããä¿è·ããŸãããŸãããªããžã§ã¯ãã®æšæºçãªã»ãã³ãã£ã¯ã¹ãå®è£ ããç¹å¥ãªã¡ãœãããå®çŸ©ããŸãã ã__ repr__ãããã³__str__ ã
è¡
ïŒ
æŒç®åã䜿çšããŠæååããã©ãŒããããã
ãã¹ãŠã®ãã©ã¡ãŒã¿ãæååã§ãã£ãŠããïŒ
æŒç®åã䜿çšããŠæååããã©ãŒãããããŸãã ïŒ
æŒç®åã®ä»£ããã«+æŒç®åã®äœ¿çšãæ
éã«æ€èšããŠãã ããã
è¯ãïŒ
æªãïŒ
次ã®ããã«ã+ããã³+ =æŒç®åã䜿çšããŠæååãã«ãŒãã«é£çµããªãã§ãã ããã æååã¯äžå€ã®ããŒã¿åã§ã;ãã®ã¢ãããŒãã¯äžèŠãªãªããžã§ã¯ããäœæããç·åœ¢æ³åã§ã¯ãªãäºæ¬¡æ³ã«åŸã£ãŠã©ã³ã¿ã€ã ãå¢å ãããŸãã 代ããã«ãåãµãã¹ããªã³ã°ããªã¹ãã«è¿œå ããã«ãŒãã®çµäºåŸã«joinã¡ãœããã䜿çšããŸãïŒãŸãã¯åãµãã¹ããªã³ã°ãcStringIO.StringIOãããã¡ãŒã«æžã蟌ã¿ãŸãïŒ
è¯ãïŒ
æªãïŒ
è€æ°è¡ã®æååã«ã¯ãããã®ä»£ããã«ããã䜿çšããŸãã ãã ãã次ã®ããã«ãæ瀺çãªæååé£çµãåžžã«äœ¿çšããããšããå§ãããŸãã è€æ°è¡ã®è¡ã¯ãåãã€ã³ãã³ãã§ããã°ã©ã ãçµäºãããŸã§ç¶ããŸããã
è¯ãïŒ
æªãïŒ
è¯ãïŒ
x = a + b x = '%s, %s!' % (imperative, expletive) x = 'name: %s; score: %d' % (name, n)
æªãïŒ
x = '%s%s' % (a, b) # use + in this case x = imperative + ', ' + expletive + '!' x = 'name: ' + name + '; score: ' + str(n)
次ã®ããã«ã+ããã³+ =æŒç®åã䜿çšããŠæååãã«ãŒãã«é£çµããªãã§ãã ããã æååã¯äžå€ã®ããŒã¿åã§ã;ãã®ã¢ãããŒãã¯äžèŠãªãªããžã§ã¯ããäœæããç·åœ¢æ³åã§ã¯ãªãäºæ¬¡æ³ã«åŸã£ãŠã©ã³ã¿ã€ã ãå¢å ãããŸãã 代ããã«ãåãµãã¹ããªã³ã°ããªã¹ãã«è¿œå ããã«ãŒãã®çµäºåŸã«joinã¡ãœããã䜿çšããŸãïŒãŸãã¯åãµãã¹ããªã³ã°ãcStringIO.StringIOãããã¡ãŒã«æžã蟌ã¿ãŸãïŒ
è¯ãïŒ
items = ['<table>'] for last_name, first_name in employee_list: items.append('<tr><td>%s, %s</td></tr>' % (last_name, first_name)) items.append('</table>') employee_table = ''.join(items)
æªãïŒ
employee_table = '<table>' for last_name, first_name in employee_list: employee_table += '<tr><td>%s, %s</td></tr>' % (last_name, first_name) employee_table += '</table>'
è€æ°è¡ã®æååã«ã¯ãããã®ä»£ããã«ããã䜿çšããŸãã ãã ãã次ã®ããã«ãæ瀺çãªæååé£çµãåžžã«äœ¿çšããããšããå§ãããŸãã è€æ°è¡ã®è¡ã¯ãåãã€ã³ãã³ãã§ããã°ã©ã ãçµäºãããŸã§ç¶ããŸããã
è¯ãïŒ
print ("This is much nicer.\n" "Do it this way.\n")
æªãïŒ
print """This is pretty ugly. Don't do this. """
ãã¡ã€ã«ãšãœã±ãã
ãã¡ã€ã«ãšãœã±ããã®äœ¿çšãçµäºããããããããæ瀺çã«éããŸã
éããŠãããã¡ã€ã«ããœã±ããããã®ä»ã®ãã¡ã€ã«åã®ãªããžã§ã¯ããç¡èŠãããšã次ã®ãããªå€ãã®å¯äœçšããããŸãã
ããããå®éã«éããããŠããå Žåãèªã¿åããŸãã¯æžã蟌ã¿ãè©Šã¿ããšäŸå€ãã¹ããŒããããããåé¡ãéåžžã«è¿ éã«æ€åºã§ããŸãã ããã«ããªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºããããšããã¡ã€ã«ãšãœã±ããã¯èªåçã«éããããŸããããªããžã§ã¯ãã®æå¹æéããã¡ã€ã«ã®ç¶æ ã«é¢é£ä»ããããšã¯ã次ã®çç±ããæªãç¿æ £ã§ãã
withã³ã³ã¹ãã©ã¯ãããµããŒããããcontextlib.closingïŒïŒã䜿çšããã«ãŒãã®ãããªãªããžã§ã¯ã
Python 2.5ã§æžãããå€ãã³ãŒãã¯ã from __ Future__ import with_statementããã®ã€ã³ããŒãã§withã³ã³ã¹ãã©ã¯ãã®äœ¿çšãæå¹ã«ããããšãã§ããŸãã ã
- ãã¡ã€ã«èšè¿°åãªã©ã®éãããã·ã¹ãã ãªãœãŒã¹ãæ¶è²»ããå¯èœæ§ããããŸãã å€ãã®ãªããžã§ã¯ãã«é¢é£ä»ããããŠããã³ãŒãã¯ã䜿çšåŸã«ã·ã¹ãã ã«è¿ãããªãå Žåããããã®ãªãœãŒã¹ãæ¯æžããŠç¡é§ã«ãªãå¯èœæ§ããããŸãã
- ãã¡ã€ã«ãéãããŸãŸã«ããŠãããšã移åãåé€ãªã©ã®ä»ã®ã¢ã¯ã·ã§ã³ããã¡ã€ã«ã«åŒãç¶ãããã®ãé²ãããšãã§ããŸãã
- ã³ãŒããä»ããŠå ¬éãããŠãããã¡ã€ã«ãšãœã±ããã¯ãè«ççã«ãéãããããåŸã«èª€ã£ãŠèªã¿æžããããå¯èœæ§ããããŸãã
ããããå®éã«éããããŠããå Žåãèªã¿åããŸãã¯æžã蟌ã¿ãè©Šã¿ããšäŸå€ãã¹ããŒããããããåé¡ãéåžžã«è¿ éã«æ€åºã§ããŸãã ããã«ããªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºããããšããã¡ã€ã«ãšãœã±ããã¯èªåçã«éããããŸããããªããžã§ã¯ãã®æå¹æéããã¡ã€ã«ã®ç¶æ ã«é¢é£ä»ããããšã¯ã次ã®çç±ããæªãç¿æ £ã§ãã
- ããã°ã©ã ã®å®è¡äžã«ãªããžã§ã¯ãã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºãããä¿èšŒã¯ãããŸããã ããŸããŸãªPythonå®è£ ã¯ãé 延ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãªã©ã®ã¡ã¢ãªç®¡çã«ããŸããŸãªã¢ãããŒãã䜿çšããããªã¢ãŒãããªããžã§ã¯ãã®å¯¿åœãå€§å¹ ã«å»¶ã°ãããšãã§ããŸãã
- ãã¡ã€ã«ãžã®äºæããªããªã³ã¯ã¯ãäºæ³ãããé·ããçããŠãããå¯èœæ§ããããŸãïŒããšãã°ãäŸå€ã¹ã¿ãã¯ãã°ããŒãã«ãªããžã§ã¯ããªã©ïŒã
- ãã¡ã€ã«ã管çããåªå çãªæ¹æ³ã¯ãwithã³ã³ã¹ãã©ã¯ãã䜿çšããããšã§ãã
with open("hello.txt") as hello_file: for line in hello_file: print line
withã³ã³ã¹ãã©ã¯ãããµããŒããããcontextlib.closingïŒïŒã䜿çšããã«ãŒãã®ãããªãªããžã§ã¯ã
import contextlib with contextlib.closing(urllib.urlopen("http://www.python.org/")) as front_page: for line in front_page: print line
Python 2.5ã§æžãããå€ãã³ãŒãã¯ã from __ Future__ import with_statementããã®ã€ã³ããŒãã§withã³ã³ã¹ãã©ã¯ãã®äœ¿çšãæå¹ã«ããããšãã§ããŸãã ã
TODOã«ããã³ã¡ã³ã
ã¿ã€ã ã³ãŒããçæãããããŸãã¯åªããŠãããå®ç§ã§ã¯ãªããœãªã¥ãŒã·ã§ã³ã«TODOã³ã¡ã³ãã䜿çšãã
TODOã³ã¡ã³ãã«ã¯ãåã³ã¡ã³ãã®å
é ã«TODOè¡ãå«ãããã®åŸã«ååãã¡ãŒã«ã¢ãã¬ã¹ããŸãã¯ãã£ãã§ç€ºãããåé¡ã®è§£æ±ºçãæäŸã§ããæåã®æ¹æ³ã®ãã®ä»ã®èå¥åãå«ããå¿
èŠããããŸãã ãã€ã³ãã¯ãªãã·ã§ã³ã§ãã ããã§äœãèµ·ããã¹ããã説æããã³ã¡ã³ãã¯å¿
èŠãããŸããã äž»ãªç®æšã¯ãTODOã®äžè¬çãªåœ¢åŒã§ããããã«ãããåé¡ã®ãã詳现ãªèª¬æãæäŸã§ããç¹å®ã®äººç©ããã°ããèŠã€ããããšãã§ããŸãã TODOã¯ã人ããã®åé¡ã解決ããããšãä¿èšŒãããã®ã§ã¯ãããŸããã ãããã£ãŠãTODOãäœæãããšãã»ãšãã©ã®å Žåãååã®ã¿ãå«ãŸããŸãã
# TODO(kl@gmail.com): Use a "*" here for string repetition. # TODO(Zeke) Change this to use relations. If your TODO is of the form "At a future date do something" make sure that you either include a very specific date ("Fix by November 2009") or a very specific event ("Remove this code when all clients can handle XML responses.").
èŒžå ¥éé¢
åã€ã³ããŒãã¯å¥ã
ã®è¡ã«ããå¿
èŠããããŸãã
è¯ãïŒ
æªãïŒ
ã€ã³ããŒãã¯åžžã«ããã¡ã€ã«ã®å é ãã¢ãžã¥ãŒã«ã¬ãã«ã®ã³ã¡ã³ããããã¥ã¡ã³ãè¡ã®çŽåŸãå®æ°ã宣èšããåã
ã¢ãžã¥ãŒã«ã¬ãã«ã®ãªããžã§ã¯ãã ã€ã³ããŒãã¯ãæãåçŽãªãã®ããæãè€éãªãã®ã®é ã«ã°ã«ãŒãåããå¿ èŠããããŸãã
ã°ã«ãŒãåã«å ããŠãã€ã³ããŒãã¯åã¢ãžã¥ãŒã«ãžã®ãã«ãã¹ã«åŸã£ãŠã倧æåãšå°æåãåºå¥ããã«èŸæžåŒã«ãœãŒãããå¿ èŠããããŸãã
import os import sys
æªãïŒ
import os, sys
ã€ã³ããŒãã¯åžžã«ããã¡ã€ã«ã®å é ãã¢ãžã¥ãŒã«ã¬ãã«ã®ã³ã¡ã³ããããã¥ã¡ã³ãè¡ã®çŽåŸãå®æ°ã宣èšããåã
ã¢ãžã¥ãŒã«ã¬ãã«ã®ãªããžã§ã¯ãã ã€ã³ããŒãã¯ãæãåçŽãªãã®ããæãè€éãªãã®ã®é ã«ã°ã«ãŒãåããå¿ èŠããããŸãã
- æšæºã©ã€ãã©ãªããã®ã€ã³ããŒã
- ãµãŒãããŒãã£ã®ã€ã³ããŒã
- ã¢ããªã±ãŒã·ã§ã³ã©ã€ãã©ãªããã€ã³ããŒããã
ã°ã«ãŒãåã«å ããŠãã€ã³ããŒãã¯åã¢ãžã¥ãŒã«ãžã®ãã«ãã¹ã«åŸã£ãŠã倧æåãšå°æåãåºå¥ããã«èŸæžåŒã«ãœãŒãããå¿ èŠããããŸãã
import foo from foo import bar from foo.bar import baz from foo.bar import Quux from Foob import ar
æ§é
åºæ¬çã«ã¯1è¡ã«1ã€ã®æ§é ã®ã¿
ãã ããããã¹ãã®çµæãæ¡ä»¶ãšåãè¡ã«é
眮ã§ããŸãã ãã ããããã¯åŒå
šäœã1è¡ã«é
眮ãããŠããå Žåã«ã®ã¿å®è¡ã§ããŸãã ç¹ã«ãtry / exceptã³ã³ã¹ãã©ã¯ãã§ãããè¡ãããšã¯ã§ããŸããã tryãšexceptãåãè¡ã«çœ®ãããšã¯ã§ããŸããããŸããifæ§æWITHOUT elseã䜿çšããŠåãè¡ã«åããããšãã§ããŸãã
è¯ãïŒ
æªãïŒ
è¯ãïŒ
if foo: bar(foo)
æªãïŒ
if foo: bar(foo) else: baz(foo) try: bar(foo) except ValueError: baz(foo) try: bar(foo) except ValueError: baz(foo)
ã¢ã¯ã»ã¹å¶åŸ¡
é衚瀺ã®ããã¹ã
ã²ãã¿ãŒé¢æ°ãåçŽãªå Žåãã²ãã¿ãŒé¢æ°ã®ãããªãã¯å€æ°ã䜿çšããŠåé¿ããå¿
èŠããããŸã
Pythonå éšåŒã³åºãã®è¿œå ãªãœãŒã¹ãªãŒããŒãããã å€ãã®æ©èœãè¿œå ããããšãããããã£ã䜿çšã§ããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ã®æŽåæ§ã远跡ããããã äžæ¹ãã²ãã¿ãŒé¢æ°ãããè€éã§ããå ŽåããŸãã¯å€æ°ãžã®ã¢ã¯ã»ã¹é床ãéåžžã«éèŠãªå Žåã¯ãget_fooïŒïŒãset_fooïŒïŒãªã©ã®é¢æ°åŒã³åºãïŒã¬ã€ãã©ã€ã³ã®æ¬¡ã®ã»ã¯ã·ã§ã³ãåç §ïŒã䜿çšããå¿ èŠããããŸãã åäœãããããã£ãä»ããã¢ã¯ã»ã¹ãèš±å¯ããå Žåãæ°ããã²ãã¿ãŒãããããã£ã«ãã€ã³ãããªãã§ãã ããã å€ãã¡ãœããã䜿çšããŠå€æ°ã«ã¢ã¯ã»ã¹ããããšããŠããã³ãŒãã¯ãã¢ã¯ã»ã¹ã®è€éããå€æŽããããšããèŠåãåãåãããšãã§ããããã«ãæ瀺çã«ã¯ã©ãã·ã¥ããå¿ èŠããããŸãã
Pythonå éšåŒã³åºãã®è¿œå ãªãœãŒã¹ãªãŒããŒãããã å€ãã®æ©èœãè¿œå ããããšãããããã£ã䜿çšã§ããŸãã
ã€ã³ã¿ãŒãã§ã€ã¹ã®æŽåæ§ã远跡ããããã äžæ¹ãã²ãã¿ãŒé¢æ°ãããè€éã§ããå ŽåããŸãã¯å€æ°ãžã®ã¢ã¯ã»ã¹é床ãéåžžã«éèŠãªå Žåã¯ãget_fooïŒïŒãset_fooïŒïŒãªã©ã®é¢æ°åŒã³åºãïŒã¬ã€ãã©ã€ã³ã®æ¬¡ã®ã»ã¯ã·ã§ã³ãåç §ïŒã䜿çšããå¿ èŠããããŸãã åäœãããããã£ãä»ããã¢ã¯ã»ã¹ãèš±å¯ããå Žåãæ°ããã²ãã¿ãŒãããããã£ã«ãã€ã³ãããªãã§ãã ããã å€ãã¡ãœããã䜿çšããŠå€æ°ã«ã¢ã¯ã»ã¹ããããšããŠããã³ãŒãã¯ãã¢ã¯ã»ã¹ã®è€éããå€æŽããããšããèŠåãåãåãããšãã§ããããã«ãæ瀺çã«ã¯ã©ãã·ã¥ããå¿ èŠããããŸãã
åœå
module_nameãpackage_name
module_nameãpackage_nameãClassNameãmethod_nameãExceptionNameãfunction_nameãGLOBAL_CONSTANT_NAMEãglobal_var_nameãinstance_var_nameãfunction_parameter_nameãlocal_var_nameã
é¿ããã¹ãååïŒ
åœåèŠå
Guidoã®æšå¥šã«åºã¥ãã¹ã¿ã€ã«ïŒ
é¿ããã¹ãååïŒ
- ã«ãŠã³ã¿ãŒãŸãã¯ã€ãã¬ãŒã¿ãŒãé€ãåäžæåã®åå
- ã¢ãžã¥ãŒã«ãšããã±ãŒãžã®ååã®çæã
- äºéã¢ã³ããŒã¹ã³ã¢ïŒååã®å é ãšæ«å°ŸïŒã¯ãèšèªçšã«äºçŽãããŠããŸãã
åœåèŠå
- ãå éšã-ã¢ãžã¥ãŒã«ã®å éšãä¿è·ã¯ã©ã¹ãŸãã¯ãã©ã€ããŒãã¯ã©ã¹ãæå³ããŸãã
- å é ã®ã¢ã³ããŒã¹ã³ã¢ïŒ_ïŒçœ®æã¯ãä¿è·ãããã¢ãžã¥ãŒã«å€æ°ããã³é¢æ°ïŒã€ã³ããŒã* fromããã€ã³ããŒããããªãïŒã§ãµããŒããããŸã
- äºéã®å é ã®ã¢ã³ããŒã¹ã³ã¢ïŒ__ïŒãå€æ°ãŸãã¯ã¡ãœããã®ååã«çœ®ãæãããšãäºå®äžããã®ã¯ã©ã¹ã«å¯ŸããŠãã©ã€ããŒãã«ãªããŸãïŒååãžã®è¿œå ã䜿çšããŸãïŒã é¢é£ããã¯ã©ã¹ãšæäžäœã¬ãã«ãã¢ãžã¥ãŒã«ã«ãŸãšããã Javaãšã¯ç°ãªãã1ã€ã®ã¢ãžã¥ãŒã«ã§1ã€ã®ã¯ã©ã¹ãäœæããããšã«å¶éããå¿ èŠã¯ãããŸããã
- ã¯ã©ã¹ã®åœåã«ã¯ã©ã¯ãè¡šèšã䜿çšããã¢ãžã¥ãŒã«åã«ã¯å€§æåãšäžç·ã䜿çšããè¡šèšã䜿çšããŸãã åœåã«ã©ã¯ãè¡šèšã䜿çšããã¢ãžã¥ãŒã«ã¯å€æ°ãããŸããã誀解ãæãå¯èœæ§ããããããããããããšã¯ãå§ãããŸããã ã¢ãžã¥ãŒã«ã¯ã¯ã©ã¹ã«ã¡ãªãã§åœåãããŸãã ïŒåŸ ã£ãŠãã€ã³ããŒãStringIOãæžããã®ã§ããããããšãStringIOã€ã³ããŒãStringIOããã§ããïŒïŒ
Guidoã®æšå¥šã«åºã¥ãã¹ã¿ã€ã«ïŒ
çš®é¡ | å€éš | 瀟å |
ããã±ãŒãž | lower_with_under | |
ã¢ãžã¥ãŒã« | lower_with_under | _lower_with_under |
ã¯ã©ã¹ | CapWords | _CapWords |
äŸå€ | CapWords | |
æ©èœ | lower_with_underïŒïŒ | _lower_with_underïŒïŒ |
ã°ããŒãã«/ã¯ã©ã¹å å®æ° | CAPS_WITH_UNDER | _CAPS_WITH_UNDER |
ã°ããŒãã«/ãµãã¯ã©ã¹å€æ° | lower_with_under | _lower_with_under |
ã¯ã©ã¹ã€ã³ã¹ã¿ã³ã¹å€æ° | lower_with_under | _lower_with_underïŒä¿è·ïŒãŸãã¯__lower_with_underïŒãã©ã€ããŒãïŒ |
ã¡ãœããå | lower_with_underïŒïŒ | _lower_with_underïŒïŒïŒä¿è·ïŒãŸãã¯__lower_with_underïŒïŒïŒãã©ã€ããŒãïŒ |
é¢æ°/ã¡ãœããã®åŒæ° | lower_with_under | |
ããŒã«ã«å€æ° | lower_with_under |
ã¡ã€ã³
ã€ã³ããŒãããããã«ãã¡ã€ã«ãäœæãããå Žåã§ã..
ã€ã³ããŒãããããã«ãã¡ã€ã«ãäœæãããå Žåã§ããéåžžã®ã€ã³ããŒãã§ã¯ãã¹ã¯ãªããã®æ©èœéšåã®å®è¡ãšãã圢ã§ã®å¯äœçšã¯ãããŸããã äž»ãªæ©èœã¯mainïŒïŒé¢æ°ã«é
眮ããå¿
èŠããããŸãã
Pythonãpycheckerãpydocãããã³åäœãã¹ãã«ã¯ãã€ã³ããŒããããã¢ãžã¥ãŒã«ãå¿ èŠã§ãã ã³ãŒãã¯ãå®è¡åã«__name__ == '__main__'ãã©ãããåžžã«ç¢ºèªããå¿ èŠããããŸããã€ãŸããã¢ãžã¥ãŒã«ãå¥ã®ããã°ã©ã ã«ã€ã³ããŒããããšãã«ãã¢ãžã¥ãŒã«ãå®å šã«å®è¡ãããªãããšãæå³ããŸãã
ã¢ãžã¥ãŒã«ãã€ã³ããŒãããããšããã¹ãŠã®æäžäœã³ãŒããå®è¡ãããŸãã é¢æ°ãåŒã³åºãããããªããžã§ã¯ããäœæããããpycheckerã䜿çšããŠãã¡ã€ã«ãæ€èšŒããããpydocã䜿çšããŠããã¥ã¡ã³ããåéãããšãã«å®è¡ãã¹ãã§ãªãä»ã®ã¿ã€ãã®æäœãå®è¡ããªãããã«æ³šæããŠãã ããã
Pythonãpycheckerãpydocãããã³åäœãã¹ãã«ã¯ãã€ã³ããŒããããã¢ãžã¥ãŒã«ãå¿ èŠã§ãã ã³ãŒãã¯ãå®è¡åã«__name__ == '__main__'ãã©ãããåžžã«ç¢ºèªããå¿ èŠããããŸããã€ãŸããã¢ãžã¥ãŒã«ãå¥ã®ããã°ã©ã ã«ã€ã³ããŒããããšãã«ãã¢ãžã¥ãŒã«ãå®å šã«å®è¡ãããªãããšãæå³ããŸãã
def main(): ... if __name__ == '__main__': main()
ã¢ãžã¥ãŒã«ãã€ã³ããŒãããããšããã¹ãŠã®æäžäœã³ãŒããå®è¡ãããŸãã é¢æ°ãåŒã³åºãããããªããžã§ã¯ããäœæããããpycheckerã䜿çšããŠãã¡ã€ã«ãæ€èšŒããããpydocã䜿çšããŠããã¥ã¡ã³ããåéãããšãã«å®è¡ãã¹ãã§ãªãä»ã®ã¿ã€ãã®æäœãå®è¡ããªãããã«æ³šæããŠãã ããã
æåŸã®èšè
é衚瀺ã®ããã¹ã
ä»ã®äººã®ã³ãŒããç·šéããŠããå Žåã¯ãæ°åãããŠãã®ã³ãŒãã調ã¹ãŠãèªåã§æžãã¹ã¿ã€ã«ãéžæããŠãã ããã , . , (#) , . , , , .
, , . , â , . .
, , . , â , . .
ããŒãžã§ã³ïŒ 2.48
ã¢ãããããã«
ã¢ã³ãã¯ãŒããã«ãŒã«
ãŠãŒãžãŒã³ãžã§ã³
ãžã§ã¬ããŒãã€ãã³
ãããã¹ããŒã
ãã€ã¯ã·ãŒã«ãº
翻蚳è ãã
ãããã質å
- PDFããŒãžã§ã³ã®ç¿»èš³ã¯éããªãäž¡æ¹ã®èšäºã«æ²èŒãããã®ã§ããèŠéããªã:)
- ããããã³ã¡ã³ãã翻蚳ããŸãããã³ãŒãå ã®ã³ã¡ã³ãã¯è±èªã§ãªããã°ãªããŸããïŒå人çã«ã¯ç§ã®æèŠã§ãïŒã
è¬èŸ
ãã°ã®ã¬ãã¥ãŒãšçºèŠã«ã€ããŠãsquaiiã«æè¬ããŸãã
ãããã«
ãé¡ãããŸã-玳士ããŸãšããªã³ãŒããæžããŠãã ããïŒããªãã®ä»äºããµããŒãããŠããã人ã®äžè©±ãããŠãã ããã圌ãã®ç®ã«åæ ãã圌ãã®åŒ·ããæãã圌ãã«äººçã®åã³ãäžãã絶ããç æ°ã®é ãšç®ã®äžã®èŒªãã解æŸããŠãã ããããåç¥ã®ããã«ãã³ãŒããäœæããŠ1ãæåŸã«ãµããŒãã«æ»ããŸãããæ¢ã«ããŒã éçºãè¡ã£ãŠãããããäœæããã³ãŒãã®ã¿ããµããŒãããå Žåã§ããééçã«äœæããã®ãæ ããªãã§ãã ãããITãããã§ãã·ã§ãã«éã®æªãæŽåããœãããŒãæ ¹çµ¶ããïŒã ãã§ãªãïŒããã¹ãŠã®äººã«è¯ãïŒ
PSïŒãããŠèŠããŠãããŠãã ããïŒ