查看: 2289|回复: 5
打印 上一主题 下一主题

[经验分享] Python静态编译器说明研究

[复制链接]
   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-1-13 10:29:05 |只看该作者 |倒序浏览

本文对Python的版本选择,IDE选择及编码的解决方案进行了一番详细的描述,实为Python初学者必读的Python学习经验心得。
AD:







使用了wxPython、pychecker编写的Python静态编译器,用于在编译器查找py脚本的错误,开放源码,与各位pythoner共享之,希望本文能给大家带来帮助,下面就一起进去Python的世界吧。
代码如下:
    def OnBuildOne(self, event):          if self.paths.count != 0:              self.Report.AppendText(self.CompileInfoHead("File"))              path = self.paths[self.List.GetSelection()]              print "Building " + path + " ..."              try:                  py_compile.compile(path, None, None)              except py_compile.PyCompileError, ex:                  print ex              self.Report.AppendText("=-- Build Finished.

")        def OnBuildAll(self, event):          if self.paths.count != 0:              self.Report.AppendText(self.CompileInfoHead("File(s)"))              for path in self.paths:                  print "Building " + path + " ..."                  try:                      py_compile.compile(path, None, None)                  except py_compile.PyCompileError, ex:                      print ex              self.Report.AppendText("=-- Build Finished.

")        def OnBuildDirectory(self, event):          dlg = wxDirDialog(self, "Select a directory for build", self.cfg[2])          if dlg.ShowModal() == wxID_OK:              path = dlg.GetPath()              self.Report.AppendText(self.CompileInfoHead("Directory:", path))              compile_dir(path, 10, None, 1, None)              self.Report.AppendText("=-- Build Finished.

")              self.cfg[2] = dlg.GetPath()                            dlg.Destroy()             def OnAbout(self, event):           dlg = wxMessageDialog(self, "resent by Dracula 2005
"                                       "Build 2005.05.05
", "About",                                       wxOK | wxICON_INFORMATION)          dlg.ShowModal()          dlg.Destroy()        def OnResize(self, event):          sizeClient = self.GetClientSize()          self.List.SetSize(sizeClient)          sizeList = self.List.GetClientSize()          self.Report.SetSize(wxSize(sizeClient.width, sizeClient.height-sizeList.height))        def OnClose(self, event):          try:              f = open("config.cfg", "w")              f.write(self.cfg[0])              if self.cfg[0][-1] != '
':                  f.write("
")              f.write(self.cfg[1])              if self.cfg[1][-1] != '
':                  f.write("
")              f.write(self.cfg[2])              f.close()          except IOError:              pass           sys.path = self.save_sys_path[:]                    self.timer.Stop()          del self.timer           del self.icon           self.Destroy()        def OnQuit(self, event):          self.Close(true)        def PyCheck(self, argv):          argv2 = ['pychecker']          argv2.append(argv)          pychecker.checker2.main(argv2)          #reload(pychecker.checker2)        def AddPath(self, path):          curdir = path         system_dir = curdir + 'datascript'          system_core_dir = curdir + 'datascriptcore'          subsystem_dir = curdir + 'datasubsystem'          subsystem_trashbin_dir = curdir + 'datasubsystem        rashbin'           sys.path = self.save_sys_path[:]          sys.path.append(curdir)          sys.path.append(system_dir)          sys.path.append(system_core_dir)          sys.path.append(subsystem_dir)          sys.path.append(subsystem_trashbin_dir)        def CompileInfoHead(self, str1, str2=""):          return "=-- %s %s Compile %s %s ...
" % (self.Date(), self.Time(), str1, str2)             def Error(self, error):          self.Report.AppendText(error)        def Output(self, info):          self.Report.AppendText(info)        def Date(self):          t = time.localtime(time.time())           strDate = time.strftime("%Y.%m.%d", t)          return strDate        def Time(self):          t = time.localtime(time.time())           strTime = time.strftime("%I:%M:%S", t)          return strTime        def Notify(self):          self.statusbar.SetStatusText(self.Date() + "   " + self.Time(), 1)    class MyApp(wxApp):  def OnInit(self):  self.frame = MyFrame(NULL, -1, "cd2Py Compiler")  self.frame.Show(true)  return true   cd2Py = MyApp(0)  import sys  class errCatcher:  def __init__(self):  pass  def write(self, stuff):  cd2Py.frame.Error(stuff)  class outCatcher:  def __init__(self):  passdef write(self, stuff):  cd2Py.frame.Output(stuff)  sys.stderr = errCatcher()  sys.stdout = outCatcher()  cd2Py.MainLoop()
纳金网:http://www.narkii.com

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

914

主题

1

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
23732
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-1-13 10:31:27 |只看该作者
看不懂的人默默走过。。。。
回复

使用道具 举报

330

主题

1

听众

1450

积分

助理设计师

Rank: 4

纳金币
1448
精华
0
板凳
发表于 2012-1-13 10:31:27 |只看该作者
先顶了收藏了,有空再研究
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2012-1-13 10:34:12 |只看该作者
来,赞一个,中午请楼主吃饭
回复

使用道具 举报

961

主题

1

听众

6万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
9

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-1-13 11:18:51 |只看该作者
看完楼主的帖子,我的心情竟是久久不能平静。正如老子所云:大音希声,大象无形。我现在终于明白我缺乏的是什么了,正是楼主那种对真理的执着追求和楼主那种对理想的艰苦实践所产生的厚重感。面对楼主的帖子,我震惊得几乎不能动弹了,楼主那种裂纸欲出的大手笔,竟使我忍不住一次次地翻开楼主的帖子,每看一次,赞赏之情就激长数分,我总在想,是否有神灵活在它灵秀的外表下,以至能使人三月不知肉味,使人有余音绕梁、三日不绝的感受。楼主,你写得实在是太好了。我惟一能做的,就只有把这个帖子顶上去这件事了。
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-7-4 23:25:14 |只看该作者
先垫一块,再说鸟
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-9-22 01:44 , Processed in 0.267386 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部