解决如何去除Python代码前行号的方法,去除python代码前行,获取Python脚本代码
解决如何去除Python代码前行号的方法,去除python代码前行,获取Python脚本代码
获取Python脚本代码前行号的方法我们已经知道了,那如何去除Python脚本代码前行号的方法又是怎样的呢?今天我们就来为大家写个实例代码来看下。
刚刚接触Python时,因为经常要在网上拷贝别人的代码回来参考学习,发现大多网站的代码前总会有数字行号,修改python代码时我们并不需要这些行号,如何快速一次性全都去除python代码行号,就是道要解决的问题了,希望今天这个去除代码前行号的方法能帮大家一些帮助。
# -*- coding: utf-8 -*-import wxclass 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''#www.iplaypy.com 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将DOC文档转换为PDF的方法源码详解,pythonpdf,分享一
- Python webbrowser调用默认浏览器打开网址的方法,pythonw
- 用Python访问读取纯真IP数据库的方法代码,pythonip,工作
- Python PycURL自动处理cookie的方法,pythonpycurl,本节要为大
- Python方法获取DLL和EXE文件版本号代码示例,pythondll,本文
- Python统计分析execl文件列表值的方法,pythonexecl,用Pyth
- Python获取web密码程序的脚本源代码,pythonweb,利用Pytho
- Python检测远端服务器端口是否通的脚本方法,python远端
- 用Python代码实现的RSS阅读器示例,pythonrss,编橙之家py
- Python方法将DBF文件导出到Excel代码示例,pythondbf,用Pyt
评论关闭