ããã«ã¡ã¯ ç§ã¯Visual StudioããŒã ã®PythonããŒã«ã®éçºè ã§ãã å æ¥ã補åã®æ°ããããŒã¿çããªãªãŒã¹ããŸããããã®æ©äŒãå©çšããŠãä»åã¯PTVSãšã¯äœãããŸãæäŸã§ãããã®ã«ã€ããŠè©³ããã話ãããããšæããŸãã
PTVSãšã¯äœã§ããïŒ
èŠããã«ãPython Studio for Visual StudioïŒä»¥éPTVSãšåŒã³ãŸãïŒã¯ããã®ååã瀺ãããã«ãVisual Studio 2010以éã®ç¡æã®æ¡åŒµæ©èœã§ããããã®IDEã«å®å šãªPythonãµããŒããè¿œå ããŸãã èªåã§èšå®ããããšã§ããã€ã©ã€ã衚瀺ãé«åºŠãªãªãŒãã³ã³ããªãŒããã³ãŒãããã²ãŒã·ã§ã³ããªãã¡ã¯ã¿ãªã³ã°ããããã°ããããã¡ã€ãªã³ã°ãDjangoã®ãµããŒããåããPythonã³ãŒãã®ç·šéãå¯èœã«ãªãã2åã®ã¯ãªãã¯ã§Windows Azureã«Webãµã€ããå ¬éã§ããŸãã åæã«ãVisual Studioã®ãã¹ãŠã®ãšãã£ã·ã§ã³ããµããŒããããææã®ProfessionalãPremiumãUltimateãããã³ç¡æã®Shellã®äž¡æ¹ã®æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ã§ããŸãã åŸè ãšçµã¿åãããŠãPTVSã¯Windowsäžã®Pythonçšã®å®å šãªç¡æéçºç°å¢ã§ãããã®ããŒãžã§ã³ã§ã¯ãVS Shell + PTVSã®äŸ¿å©ãªçµåã€ã³ã¹ããŒã©ãŒãäœæããŸããã Visual Studio 2013 Previewãæ¢ã«ã€ã³ã¹ããŒã«ããŠããå Žåã¯ã[æ°ãããããžã§ã¯ã]ãã€ã¢ãã°ã§æ¬¡ã®ããšãã§ããŸãïŒ
ç§ãã¡ã®ãããžã§ã¯ãã¯ãããã€ãã®ç¹ã§ããã€ã¯ããœããç¬èªã®ãã®ã§ãã ïŒApache License 2.0ã®äžã§ã®ïŒãªãŒãã³ãœãŒã¹ã®ãœãŒã¹ã³ãŒãã¯ã誰ã«ãé©ãããšã¯ãããŸãããããœãŒã¹ã³ãŒããCodePlexã§å ¬éããã ãã§ãªããå šå¡ããããžã§ã¯ãã«ååããããæåŸ ããŠããŸã ã ã¯ããã¯ãããµãŒãããŒãã£ã®ã³ãŒããåãå ¥ããŸãïŒ
æåŸã«ããã®ç¹ã«é¢ããŠãã°ãã°æ··ä¹±ãçãããããPTVSã¯IronPythonã§ã¯ãªããIronPythonã®ã¿ã«çŠç¹ãåœãŠãç°å¢ã§ã¯ãããŸããã ã»ãŒãã¹ãŠã®Pythonå®è£ ïŒCPythonãIronPythonãJythonãPyPyãStacklessïŒãããçšåºŠãµããŒãããŠããŸãããåªå é äœã¯æšæºããµããŒãããããšã§ãããã»ãšãã©ã®Pythonéçºè ã§ããCPythonã€ã³ã¿ãŒããªã¿ãŒã§äœ¿çšãããŠããŸãã
次ã«ãPTVSã®ããã€ãã®æãèå³æ·±ããŠããŒã¯ãªæ©èœãããã«è©³ããæ€èšããŸãã
ã³ãŒããæäœãã
ãããããã¹ãŠã®éçºè ã«ãšã£ãŠããŸã第äžã«ãIDEãéžæããäžã§æ±ºå®çãªã®ã¯ã³ãŒãã§äœæ¥ããããšã®å©äŸ¿æ§ã§ãã ãã®ããããªãŒãã³ã³ããªãŒãããªãã¡ã¯ã¿ãªã³ã°ãã·ã³ãã«æ€çŽ¢ããã®ä»ã®äž»èŠãªæ©èœãå®è£ ãããŠããPythonã³ãŒãã解æããããã®é«åºŠãªãšã³ãžã³ããPTVSãããžã§ã¯ãã®äžéšãšããŠäœæãããæåã®ãšã³ãžã³ã§ããã æ°ããããŒãžã§ã³ããšã«ã解æã®å質ãåäžããããŒã¿2.0ãäŸå€ã§ã¯ãããŸããã
ä»æ¥ãåçã«åä»ããããèšèªã®åçŽãªèªåè£å®ã§èª°ãé©ããã人ã¯ããŸããããå€ãã®ç·šéè ã¯ãèšèªã®åçãªæ©èœã䜿çšããäºçŽ°ãªäŸã§ãããã¹ããããããŸãã ããšãã°ã次ã®ã³ãŒããã芧ãã ããã
def f(x): def g(y): return x + y return g a = f(1)(2) b = f(3.0)(a) c = f(u'a')(str(b)) d = (a, b, c)[input()]
Pythonã®å ç®æŒç®åã¯å€æ çã§ãããããgã«ãã£ãŠè¿ãããå€ã®ã¿ã€ã-çµæãšããŠãaãbãããã³cã®å€ã®ã¿ã€ã-ã¯ãæž¡ãããåŒæ°ã®ã¿ã€ãã®ã¿ã«äŸåããŸãã ã¿ã€ãdã¯ãåã®3ã€ã®å€æ°ãã¹ãŠã®ã¿ã€ãã«éæ¥çã«äŸåãããããæãè€éã§ãããã®å Žåããšãã£ã¿ãŒã¯æåã«ã¿ãã«ãã¢ã»ã³ãã«ããŠãã解æããå¿ èŠããããŸãã
PTVSã¯ãæž¡ãããåŒæ°ã®ä»¥åã«æŽŸçããåãåæãšããŠãç¹å®ã®ååŒã³åºãã®åãäžæã«æ±ºå®ããããšããŸãã ãã®ã³ãŒãã®ããŸããŸãªå€æ°ã«ã€ããŠãšãã£ã¿ãŒã«è¡šç€ºããããã³ããšã¢ããªã³ã¯æ¬¡ã®ãšããã§ãã
ã芧ã®ãšãããåŸè ã®å Žåãå€æ°ã«ã¯ããã€ãã®æœåšçãªã¿ã€ããããããªãŒãã³ã³ããªãŒãã¯ããããã¹ãŠã衚瀺ããŸãã
äžæ¹ãæ¬äœã®é¢æ°ãã©ã¡ãŒã¿ãŒã®ãã³ããèŠæ±ããå Žåã¯ãåæšè«ã®çµæã確èªããããšãã§ããŸãã
ããã§ã¯ãé¢æ°ãã³ãŒãå ã®ã©ããã§åŒã³åºããããã¹ãŠã®ã¿ã€ãã®åŒæ°ãåéãããŸã-é¢æ°ã®æ¬äœã§ã®åŒæ°ã®èªåè£å®ã¯ãããã«å¿ããŠæ©èœããŸãã ããã«ã¯èå³æ·±ãçµæããããŸããTDDã䜿çšããæåã«é¢æ°ãšã¯ã©ã¹ã®ãã¹ããäœæããŠããå®è£ ãããšããã¹ãŠã®ãã©ã¡ãŒã¿ãŒã®æ£ããèªåè£å®ãèªåçã«åãåããŸãã
èªåè£å®ã«å ããŠãå€æ°ã®å®£èšãšåç §ã®æ€çŽ¢ãæ©èœããŸãã ããã§ãPTVSã«ã¯èå³æ·±ãè¿œå ã1ã€ãããŸã-æ€çŽ¢ãéå§ãããå€æ°ãé¢æ°ãŸãã¯ã¯ã©ã¹ãåç §ããïŒãŸãã¯åç §ã§ããïŒå Žåãæ€çŽ¢çµæã§ã¯ããã®å€æ°ã«å€ãå²ãåœãŠãããè¡ã«å ããŠããããã®é¢æ°ã®åæ宣èšããããŸãããã³ã¯ã©ã¹-å€ãçŽæ¥å²ãåœãŠãããªãã£ãå Žåã§ãã ããšãã°ãäžèšã®ã³ãŒãã«æ¬¡ã®è¡ãè¿œå ããå ŽåïŒ
h = f if input() else f(a) print h(b)
hã§Find All Referencesã³ãã³ããå®è¡ãããšã次ã®çµæãåŸãããŸãã
ã芧ã®ãšãããé¢æ°gã¯åŒã³åºãfïŒaïŒã§ãã£ãããããªã¹ãã«è¡šç€ºãããŸãã ãã¡ãããããã¯hãåŒã³åºãããšãããšãã®èªåè£å®ã®çµæã«åæ ãããŸã-ææ¡ããã眲åãªãã·ã§ã³ã§ã¯ãfãšgã®ãã¹ãŠã®æ¢ç¥ã®ãªãã·ã§ã³ã衚瀺ãããŸãã
æ··åã³ãŒãã®ãããã°
ããŒã¿2.0å°çš-ããã¯ä»ã«ãããŸããã ããã¯ã1æã®åçã«æ°åèªã®äŸ¡å€ãããå Žåã§ãã ããã«ãããŸãïŒ
ãã®ã¹ã¯ãªãŒã³ã·ã§ããã¯ãCïŒããã°ã©ã ã«æ¥ç¶ããããããã¬ãŒã瀺ããŠãããCPythonãCPythonèªäœã«ããŒãããC ++ã§èšè¿°ãããæ¡åŒµã¢ãžã¥ãŒã«ãããŒãããŸããããã3ã€ã®ãã¹ãŠã¯ãããªãæ··ä¹±ããæ¹æ³ã§ãäºããåŒã³åºããŸããåŒã³åºãã¹ã¿ãã¯ã ãã¡ããããã¹ãŠã®ãããžã§ã¯ãã§ãã¬ãŒã¯ãã€ã³ããäœæã§ããŸããããã®ãããªè€åã¢ãŒããæäŸããæãéèŠãªããšã¯ãå€èšèªåŒã³åºãã®æ®µéçãªãããã°ã®å¯èœæ§ã§ãã ããšãã°ãC ++ã§å®è£ ãããã¯ã©ã¹ã®ã¡ãœãããåŒã³åºãPythonã³ãŒãã®è¡ã§[ã¹ãããã€ã³]ã³ãã³ããå®è¡ãããšããã®ã¡ãœããã®ãœãŒã¹ã衚瀺ãããŸãã åæ§ã«ãããã¯Pythonã§èšè¿°ãããé¢æ°ã®PyObject_CallObjectãåŒã³åºãC ++ãŸãã¯CïŒã³ãŒãã§æ©èœããŸãã ãã€ãã£ãã³ãŒãã®åŒã³åºãã¯ãctypesãä»ããéåžžã®åçã©ã€ãã©ãªã§ããµããŒããããŠããŸãã
ã¹ã¯ãªãŒã³ã·ã§ããã¯3ã€ã®èšèªã®åæãããã°ã瀺ããŠããŸãããå®éã«ã¯ã»ãšãã©ã®å ŽåãPythonãšC ++ïŒãŸãã¯CïŒã®2ã€ã«å¶éãããŠããŸã-æ¡åŒµã¢ãžã¥ãŒã«ã䜿çšããPythonããã°ã©ã ããã¹ã¯ãªããèšèªãšããŠPythonã䜿çšããC ++ããã°ã©ã ã®ããããã§ãã ãã®ãããC / C ++ã§ã®ã¿å©çšå¯èœãªå€ãã®æ©èœããããã¬ã«è¿œå ããŸããã ã¹ã¯ãªãŒã³ã·ã§ããã®[ããŒã«ã«]ãŠã£ã³ããŠãšãC ++ã§å®è£ ãããã¯ã©ã¹ã®ãªããžã§ã¯ããåç §ããå€æ°a_natobjã®å€ã®æ¡åŒµè¡šçŸã«æ³šæããŠãã ããããªããžã§ã¯ãã®Pythonè¡šçŸãšåæã«ãC ++ïŒã¯ã©ã¹ãå®è£ ããæ§é ã®è¡šçŸïŒã衚瀺ãããŸãã C ++åŽããã®Pythonãªããžã§ã¯ãã®ãã©ãŒã€ã¡ãŒãžããããŸã-ããã¯ãåãLocalsãŠã£ã³ããŠãfrobé¢æ°ã§ã©ã®ããã«èŠãããã§ãïŒ
ã芧ã®ãšãããC ++ã§PyObjectïŒãŸãã¯Python APIã®ãã®ä»ã®æšæºåïŒãšããŠå®£èšãããå€æ°ã®å€ã¯ããããã®ãªããžã§ã¯ãã®Pythonãã¥ãŒã察å¿ããCæ§é äœã®ãã£ãŒã«ããšåæã«è¡šç€ºããŸãã
REPLã®ãããã°
Pythonã®éåžžã®REPLã®ååšã¯IDEã®æšæºã§ãããPTVSãäŸå€ã§ã¯ãããŸãã-ãã¡ãããæ§æã®åŒ·èª¿è¡šç€ºãšèªåè£å®ããµããŒãããŸãïŒåŸè ã¯ãå¯èœã§ããã°ãã¡ã¢ãªå ã®å€ãšçŽæ¥é£æºããŠé©åãªãã³ããæäŸããŸãïŒ ã ããããã³ãŒãã®ãããã°æã«ããã«ãã©ã€ããREPLããµããŒãããŸãããã€ãŸããREPLã¯ãããã°ãããããã»ã¹ã®ããŒã¿ã«çŽæ¥äœçšããè€éãªåŒããã®å Žã§è©äŸ¡ããã¯ã©ã¹ãšé¢æ°ãåå®çŸ©ã§ããŸãã ãã®èšäºã®æåã®äŸã®ãããã°REPLã®ã¹ã¯ãªãŒã³ã·ã§ããã次ã«ç€ºããŸãã
DjangoãšWindows Azure
PTVSã¯ãDjangoã§ã®Webã¢ããªã±ãŒã·ã§ã³ã®äœæããµããŒãããæ§æ匷調衚瀺ãã³ãŒãè£å®ãããã³è¡šç€ºãã³ãã¬ãŒãã®ãããã°ãæäŸããŸãã
ãŸãããã®ããŒãžã§ã³ã®PTVSããããã®æ¹æ³ã§äœæãããã¢ããªã±ãŒã·ã§ã³ã¯ã以åã¯ASP.NETã§ããå©çšã§ããªãã£ãç°¡åãªæ¹æ³ã§ã Windows Azureã® Webãµã€ãã«å ¬éã§ããŸãã
ã»ãïŒ
ã¯ããAzure Webãµã€ãã¯PythonããµããŒãããããã«ãªããŸãã ïŒ Azureã®ä»ã®æ©èœïŒããŒãã«ãµãŒãã¹ãããããµãŒãã¹ããµãŒãã¹ãã¹ãã¹ãã¬ãŒãžãã¥ãŒãªã©ïŒã䜿çšã§ããŸãã -å ¬åŒã®Windows Azure SDK for Pythonã䜿çšããPythonã¢ããªã±ãŒã·ã§ã³ã§ãç§ãã¡ã®ããŒã ãåãçµãã§ããŸãã ãã ããSDKã¯ã¯ãã¹ãã©ãããã©ãŒã ã§ãããã®ããã®å¯äžã®èŠä»¶ã¯Python 2.6以äžã§ãã
ãããã¡ã€ãªã³ã°
ãããŠåã³ãã¹ã¯ãªãŒã³ã·ã§ããã¯èšèãããã¯ããã«å€ããèªããŸãïŒ
...ãªã©ãªã©ïŒ
PTVSæ©èœã¯äžèšã«éå®ãããŸãã-ãªãã¡ã¯ã¿ãªã³ã°ãpipããã³easy_installã«ããvirtualenvããã³ããã±ãŒãžç®¡çã®æäœãLinuxããã³OS Xã§ã®ããã°ã©ã ã®ãªã¢ãŒããããã°ãREPLã§ã®IPythonãµããŒãïŒã°ã©ãã®èŠèŠåïŒãªã©ã®èå³æ·±ãæ©èœããããŸãã MPIã¯ã©ã¹ã¿ãŒã§ã®Pythonã³ãŒãã®ãããã°ãšãããã¡ã€ãªã³ã°ã ãããžã§ã¯ãã®ããã¥ã¡ã³ãããŒãžã§è©³çŽ°ãèªããã ã¬ãã¥ãŒãããªãèŠãããšãã§ããŸã ã
ããªãã®æèŠã¯ç§éã«ãšã£ãŠéåžžã«éèŠã§ãã
ããããçå£ã«ãããã¯æ¬åœã«éèŠã§ãïŒ ãªãŒãã³ãªãã°ãã©ãã«ãŒããã ããã®äžã®ãŠãŒã¶ãŒããã®ãã°ã¬ããŒããšææ¡ããã€ã§ã確èªã§ããŸãã ææ¡ã«é¢ããŠã¯-ããã¯ç©ºã®ãã¬ãŒãºã§ã¯ãããŸããã æ°ããããŒãžã§ã³ã®äœæãéå§ãããã®å 容ã決å®ãããšããæåã«è¡ãããšã¯ããã©ãã«ãŒã§æ©èœèŠæ±ãªã¹ããéãããŠãŒã¶ãŒã®æ祚ã§ãœãŒãããäžèšã®å 容ã確èªããããšã§ãã ãã®ãããããŒãžã§ã³2.0ã§ã¯ãããã10ãã5ã€ã®æ©èœãå®è£ ããŸããããã®ãã¡ã®3ã€ã¯æåã®3ã€ã®å Žæã«ãããŸããã 質åãããããäœããè°è«ãããå Žåã¯ã ãã©ãŒã©ã ã§ãããè¡ãããšãã§ããŸãã ãããŠããã¡ãããç§ã¯ãã®èšäºãžã®ã³ã¡ã³ãã§ããªãã®è³ªåã«çãããã§ãã