成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Python靜態編譯器說明研究

開發 后端
本文對Python的版本選擇,IDE選擇及編碼的解決方案進行了一番詳細的描述,實為Python初學者必讀的Python學習經驗心得。

使用了wxPython、pychecker編寫的Python靜態編譯器,用于在編譯器查找py腳本的錯誤,開放源碼,與各位pythoner共享之,希望本文能給大家帶來幫助,下面就一起進去Python的世界吧。

代碼如下:

  1.     def OnBuildOne(self, event):  
  2.         if self.paths.count != 0:  
  3.             self.Report.AppendText(self.CompileInfoHead("File"))  
  4.             path = self.paths[self.List.GetSelection()]  
  5.             print "Building " + path + " ..."  
  6.             try:  
  7.                 py_compile.compile(path, None, None)  
  8.             except py_compile.PyCompileError, ex:  
  9.                 print ex  
  10.             self.Report.AppendText("=-- Build Finished.\n\n")  
  11.  
  12.  
  13.     def OnBuildAll(self, event):  
  14.         if self.paths.count != 0:  
  15.             self.Report.AppendText(self.CompileInfoHead("File(s)"))  
  16.             for path in self.paths:  
  17.                 print "Building " + path + " ..."  
  18.                 try:  
  19.                     py_compile.compile(path, None, None)  
  20.                 except py_compile.PyCompileError, ex:  
  21.                     print ex  
  22.             self.Report.AppendText("=-- Build Finished.\n\n")  
  23.  
  24.  
  25.     def OnBuildDirectory(self, event):  
  26.         dlg = wxDirDialog(self, "Select a directory for build", self.cfg[2])  
  27.         if dlg.ShowModal() == wxID_OK:  
  28.             path = dlg.GetPath()  
  29.             self.Report.AppendText(self.CompileInfoHead("Directory:", path))  
  30.             compile_dir(path, 10, None, 1, None)  
  31.             self.Report.AppendText("=-- Build Finished.\n\n")  
  32.             self.cfg[2] = dlg.GetPath()  
  33.                   
  34.         dlg.Destroy()  
  35.       
  36.  
  37.     def OnAbout(self, event):   
  38.         dlg = wxMessageDialog(self, "Present by Dracula 2005\n"   
  39.                                     "Build 2005.05.05\n", "About",   
  40.                                     wxOK | wxICON_INFORMATION)  
  41.         dlg.ShowModal()  
  42.         dlg.Destroy()  
  43.  
  44.  
  45.     def OnResize(self, event):  
  46.         sizeClient = self.GetClientSize()  
  47.         self.List.SetSize(sizeClient)  
  48.         sizeList = self.List.GetClientSize()  
  49.         self.Report.SetSize(wxSize(sizeClient.width, sizeClient.height-sizeList.height))  
  50.  
  51.  
  52.     def OnClose(self, event):  
  53.         try:  
  54.             f = open("config.cfg", "w")  
  55.             f.write(self.cfg[0])  
  56.             if self.cfg[0][-1] != '\n':  
  57.                 f.write("\n")  
  58.             f.write(self.cfg[1])  
  59.             if self.cfg[1][-1] != '\n':  
  60.                 f.write("\n")  
  61.             f.write(self.cfg[2])  
  62.             f.close()  
  63.         except IOError:  
  64.             pass  
  65.  
  66.         sys.path = self.save_sys_path[:]  
  67.           
  68.         self.timer.Stop()  
  69.         del self.timer   
  70.         del self.icon   
  71.         self.Destroy()  
  72.  
  73.  
  74.     def OnQuit(self, event):  
  75.         self.Close(true)  
  76.  
  77.  
  78.     def PyCheck(self, argv):  
  79.         argv2 = ['pychecker']  
  80.         argv2.append(argv)  
  81.         pychecker.checker2.main(argv2)  
  82.         #reload(pychecker.checker2)  
  83.  
  84.  
  85.     def AddPath(self, path):  
  86.         curdir = path 
  87.         system_dir = curdir + '\\data\\script'  
  88.         system_core_dir = curdir + '\\data\\script\\core'  
  89.         subsystem_dir = curdir + '\\data\\subsystem'  
  90.         subsystem_trashbin_dir = curdir + '\\data\\subsystem\\trashbin'  
  91.  
  92.         sys.path = self.save_sys_path[:]  
  93.         sys.path.append(curdir)  
  94.         sys.path.append(system_dir)  
  95.         sys.path.append(system_core_dir)  
  96.         sys.path.append(subsystem_dir)  
  97.         sys.path.append(subsystem_trashbin_dir)  
  98.  
  99.  
  100.     def CompileInfoHead(self, str1, str2=""):  
  101.         return "=-- %s %s Compile %s %s ...\n" % (self.Date(), self.Time(), str1, str2)  
  102.       
  103.  
  104.     def Error(self, error):  
  105.         self.Report.AppendText(error)  
  106.  
  107.  
  108.     def Output(self, info):  
  109.         self.Report.AppendText(info)  
  110.  
  111.  
  112.     def Date(self):  
  113.         t = time.localtime(time.time())   
  114.         strDate = time.strftime("%Y.%m.%d", t)  
  115.         return strDate  
  116.  
  117.  
  118.     def Time(self):  
  119.         t = time.localtime(time.time())   
  120.         strTime = time.strftime("%I:%M:%S", t)  
  121.         return strTime  
  122.  
  123.  
  124.     def Notify(self):  
  125.         self.statusbar.SetStatusText(self.Date() + "   " + self.Time(), 1)  
  126.  
  127.  
  128. class MyApp(wxApp):  
  129. def OnInit(self):  
  130. self.frame = MyFrame(NULL, -1, "cd2Py Compiler")  
  131. self.frame.Show(true)  
  132. return true   
  133. cd2Py = MyApp(0)  
  134. import sys  
  135. class errCatcher:  
  136. def __init__(self):  
  137. pass  
  138. def write(self, stuff):  
  139. cd2Py.frame.Error(stuff)  
  140. class outCatcher:  
  141. def __init__(self):  
  142. passdef write(self, stuff):  
  143. cd2Py.frame.Output(stuff)  
  144. sys.stderr = errCatcher()  
  145. sys.stdout = outCatcher()  
  146. cd2Py.MainLoop() 

【編輯推薦】

  1. 如何使Python嵌入C++應用程序?
  2. 深入探討Ruby與Python語法比較
  3. Python學習資料介紹分享
  4. Python學習經驗談:版本、IDE選擇及編碼解決方案
  5. 淺析Python的GIL和線程安全
責任編輯:chenqingxiang 來源: 人民郵電出版社
相關推薦

2010-02-02 17:08:26

Python靜態編譯器

2010-01-18 10:34:21

C++編譯器

2010-01-28 15:56:38

VC++ 6.0編譯

2010-02-03 15:30:03

IronPython

2023-07-31 07:33:04

Rust編譯器內存

2010-01-13 17:12:26

C++編譯器

2010-03-23 11:17:16

Python 動態編譯

2022-12-28 08:52:15

編譯器自動內存管理

2021-03-15 14:54:47

編譯器工具代碼

2010-01-13 14:35:10

Visual C++

2021-10-17 19:52:40

Python:源碼編譯器

2010-01-21 09:11:38

C++編譯器

2009-08-10 17:12:54

C#編譯器

2017-03-20 18:01:55

編譯器匯編

2013-03-29 10:02:37

編譯器語言編譯開發

2009-12-11 15:38:40

VS2008編譯器

2020-01-10 18:04:01

Python編程語言Windows

2010-10-20 13:43:37

C++編譯器

2019-08-06 08:20:07

編譯器工具開發者

2010-02-23 15:44:24

Python編輯器
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人精品国产免费网站 | 免费黄色的视频 | 羞羞视频在线观看 | 亚洲小视频在线观看 | 久久久久久高清 | 黄视频网站在线 | 欧美精品在线一区 | 亚洲精品视频在线播放 | 国产精品一区二区在线播放 | 亚洲国产欧美91 | 天天躁日日躁狠狠躁白人 | 美女在线视频一区二区三区 | 欧美色综合一区二区三区 | 91精品国产手机 | 久久精品一区 | 一级在线 | 羞羞视频一区二区 | 中文字幕 亚洲一区 | 欧美日日 | 欧美一区二区三区的 | 日本精品久久久久久久 | 久久99精品久久久97夜夜嗨 | 亚洲日本成人 | 久草欧美视频 | 91麻豆精品国产91久久久更新资源速度超快 | 男女视频在线免费观看 | 日韩精品一区二区三区中文在线 | 国产精品久久久一区二区三区 | 免费久久精品视频 | 国产成都精品91一区二区三 | 九色porny自拍视频 | 青青操av | 黄色在线观看网址 | 久久久久久久久久影视 | 国产精品日女人 | 国产精品久久国产精品 | 亚洲视频www | 一区二区三区四区电影 | 亚洲视频一区在线 | 欧美第一页 | 欧美一级欧美一级在线播放 |