Python实现去除代码前行号的方法
2015-03-10 00:00
801 查看
本文实例讲述了Python实现去除代码前行号的方法。分享给大家供大家参考。具体实现方法如下:
希望本文所述对大家的Python程序设计有所帮助。
# -*- coding: utf-8 -*- import wx class MainWindow(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, u'去除代码前行号的Python小工具 - wxPython版 - Develop by Yanxy') self.textBox = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE,size=(600,600)) self.butOK = wx.Button(self, label=u"去除行号") self.butLeft = wx.Button(self, label=u"去除左侧一个字符") self.Bind(wx.EVT_BUTTON, self.CutLineNum, self.butOK) self.Bind(wx.EVT_BUTTON, self.CutLeftChar, self.butLeft) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(self.textBox,1,wx.EXPAND) self.sizer.Add(self.butOK) self.sizer.Add(self.butLeft) self.SetSizer(self.sizer) self.SetAutoLayout(1) self.sizer.Fit(self) self.Show(True) def OnCloseWindow(self, event): self.Destroy() def CutLineNum(self, event): multiStr = unicode(self.textBox.GetValue()).splitlines(1) outStr = u'' for singleStr in multiStr: singleStr = singleStr.lstrip() i=0 for charStr in singleStr: if charStr.isdigit(): i += 1 elif i>0: singleStr = singleStr[i:] break else: break outStr += singleStr self.textBox.SetValue(outStr) def CutLeftChar(self, event): outStr = u'' multiStr = unicode(self.textBox.GetValue()).splitlines(1) for singleStr in multiStr: singleStr = singleStr[1:] outStr += singleStr self.textBox.SetValue(outStr) if __name__ == '__main__': app = wx.PySimpleApp() frame = MainWindow(parent=None, id=-1) app.MainLoop() del app
希望本文所述对大家的Python程序设计有所帮助。
相关文章推荐
- Python实现去除代码前行号的方法
- 用python实现的去除win下文本文件头部BOM的代码
- 代码中去除行号的方法
- python实现统计代码行数的方法
- Python实现统计代码行的方法分析
- python去除空格和换行符的实现方法(推荐)
- Java入门学习:实现日志方法(记录代码文件名,类名,方法名,行号)
- 实现python代码的动态删除多余的日志文件(非自带滚动日志方法)
- Python实现字典去除重复的方法示例
- python代码实现简易滤除数字方法
- 利用Python代码实现数据可视化的5种方法详解
- Notepad++去除代码行号的几种方法
- Python实现比较两个文件夹中代码变化的方法
- Java编程实现获取当前代码行行号的方法示例
- python_获取当前代码行号_获取当前运行的类名和函数名的方法
- python实现统计代码行数的方法
- 拷贝的代码中去除行号的方法
- 批处理与python代码混合编程的实现方法
- 【廖雪峰 python教程 课后题 切片】利用切片操作,实现一个trim()函数,去除字符串首尾的空格,注意不要调用str的strip()方法:
- 【廖雪峰 python教程 课后题 切片】利用切片操作,实现一个trim()函数,去除字符串首尾的空格,注意不要调用str的strip()方法: