去除每一行代码前的数字行标(字符串形式)

有的时候自己需要的代码前面有一些奇怪的行标,这样会导致cv战士无法快速运行想要的代码

下面就是去除每一行前面的数字行标的python实现

替换s为需要的代码即可(按照自己需要删去的数量自行调整)

s=""" 1 def Login():
 2     global Flag
 3     try:
 4         bot.Login(['-q',v1.get()])
 5         tkinter.messagebox.showinfo(message="登陆成功")
 6         Flag=1
 7     except Exception as e:
 8         tkinter.messagebox.showerror(message=str(e))
 9 def Send():
10     global Flag
11     if Flag==0:
12         tkinter.messagebox.showwarning(message='您还没有登陆,不能发送消息!')
13         return ''
14     content= T1.get(1.0, tkinter.END)
15     if vOption.get() == 1:
16         Friends=bot.List('buddy')
17     elif vOption.get() == 2:
18         Friends = bot.List('group')
19     for friend in Friends:
20         if v2.get() in friend.name:
21             try:
22                 bot.SendTo(friend, content)
23             except Exception as e:
24                 tkinter.messagebox.showerror(message=str(e))
25     tkinter.messagebox.showinfo(message="发送完毕")
26 if __name__ == '__main__':
27     root = tkinter.Tk()
28     L1 = tkinter.Label(root, text='QQ账号')
29     L1.place(x=10,y=10,height=30)
30     v1 = tkinter.StringVar()
31     E1 = tkinter.Entry(root, textvariable=v1)
32     E1.place(x=60,y=10,width=120,height=30)
33     B1 = tkinter.Button(root, text='登陆', command=Login)
34     B1.place(x=190,y=10,width=50,height=30)
35     vOption = tkinter.IntVar(value=1)
36     R1 = tkinter.Radiobutton(root, text='发给所有好友', variable=vOption, value=1)
37     R1.place(x=10,y=50)
38     R2 = tkinter.Radiobutton(root, text='发给所有群', variable=vOption, value=2)
39     R2.place(x=10,y=70)
40     L2 = tkinter.Label(root, text='名称包含')
41     L2.place(x=130,y=60)
42     v2 = tkinter.StringVar()
43     E2 = tkinter.Entry(root, textvariable=v2)
44     E2.place(x=190,y=60,width=50)
45     T1 = tkinter.Text(root)
46     T1.place(x=10,y=110,width=230,height=100)
47     B1 = tkinter.Button(root, text='发送', command=Send)
48     B1.place(x=10, y=220, width=230, height=30)
49     Flag=0
50     root.resizable(False, False)
51     root.geometry('250x250+300+300')
52     root.mainloop()"""

str_list = s.split(sep='\n')
ha = ""

for i in str_list:
    ha = ha + i[3:] + "\n"
#需要在i后面修改前面的需要删去的数量
print(ha)

输出结果:

def Login():
    global Flag
    try:
        bot.Login(['-q',v1.get()])
        tkinter.messagebox.showinfo(message="登陆成功")
        Flag=1
    except Exception as e:
        tkinter.messagebox.showerror(message=str(e))
def Send():
    global Flag
    if Flag==0:
        tkinter.messagebox.showwarning(message='您还没有登陆,不能发送消息!')
        return ''
    content= T1.get(1.0, tkinter.END)
    if vOption.get() == 1:
        Friends=bot.List('buddy')
    elif vOption.get() == 2:
        Friends = bot.List('group')
    for friend in Friends:
        if v2.get() in friend.name:
            try:
                bot.SendTo(friend, content)
            except Exception as e:
                tkinter.messagebox.showerror(message=str(e))
    tkinter.messagebox.showinfo(message="发送完毕")
if __name__ == '__main__':
    root = tkinter.Tk()
    L1 = tkinter.Label(root, text='QQ账号')
    L1.place(x=10,y=10,height=30)
    v1 = tkinter.StringVar()
    E1 = tkinter.Entry(root, textvariable=v1)
    E1.place(x=60,y=10,width=120,height=30)
    B1 = tkinter.Button(root, text='登陆', command=Login)
    B1.place(x=190,y=10,width=50,height=30)
    vOption = tkinter.IntVar(value=1)
    R1 = tkinter.Radiobutton(root, text='发给所有好友', variable=vOption, value=1)
    R1.place(x=10,y=50)
    R2 = tkinter.Radiobutton(root, text='发给所有群', variable=vOption, value=2)
    R2.place(x=10,y=70)
    L2 = tkinter.Label(root, text='名称包含')
    L2.place(x=130,y=60)
    v2 = tkinter.StringVar()
    E2 = tkinter.Entry(root, textvariable=v2)
    E2.place(x=190,y=60,width=50)
    T1 = tkinter.Text(root)
    T1.place(x=10,y=110,width=230,height=100)
    B1 = tkinter.Button(root, text='发送', command=Send)
    B1.place(x=10, y=220, width=230, height=30)
    Flag=0
    root.resizable(False, False)
    root.geometry('250x250+300+300')
    root.mainloop()

给自己的代码每一行前面加上行标_long_songs的博客-CSDN博客icon-default.png?t=M0H8https://blog.csdn.net/long_songs/article/details/122741770

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值