Python实现去除代码前行号的方法
程序员文章站
2022-05-12 15:13:52
...
本文实例讲述了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
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程序设计有所帮助。
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
上一篇: 利用html怎么判断IE版本?
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论