拆分字符串导致GUI崩溃?

2024-09-26 18:18:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码,出于某种原因导致Python GUI在打印行时崩溃:

urlstr = str(URLS)
        a = urlstr.split('=', 2)
        print('a=', a)

URL是从字典生成的URL,而字典又是从一系列文本文件的值创建的。我从URL中创建一个字符串,然后尝试在第二个等号处拆分它。你知道吗

如果删除print语句,代码运行正常,但传递给'a'的条件逻辑不会产生值。你知道吗

我真的很困惑,谁能看出来问题是什么。你知道吗

谢谢


Tags: 字符串代码url字典gui语句urlssplit
1条回答
网友
1楼 · 发布于 2024-09-26 18:18:23

我认为您正在使用空闲的Python shell和线程。如果我错了,请纠正我。你知道吗

有时这会导致Tkinter/怠速崩溃。你知道吗

下面是我在2008年编写的一些代码,用于防止Python Shell在使用线程时崩溃。你知道吗

## das muss in idlelib.PyShell in die letzten Zeilen der Klasse
## this must be copied  to idlelib.PyShell into the last lines of the class


#############################  adds by nicco kunzmann  #########################

    __nk___init__= __init__
    def __init__(self, *args, **kw):
        self.__nk___init__(*args, **kw)
        self.__nk_writelist= []
        self.__nk_act_act_write()

    __nk_write= write
    def write(self, *args):
        self.__nk_writelist.append(args)

    def __nk_act_act_write(self):
        try:
            while self.__nk_writelist:
                args= self.__nk_writelist.pop(0)
                try:
                    self.__nk_write(*args)
                except:
                    traceback.print_exception(*sys.exc_info())
                    print args

        finally:
            self.text.after(1, self.__nk_act_act_write)


#############################  adds  by  n.k. the end  #########################

相关问题 更多 >

    热门问题