| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1152 人关注过本帖, 1 人收藏
标题:求助将循环简化为无限循环
只看楼主 加入收藏
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
结帖率:87.5%
收藏(1)
已结贴  问题点数:20 回复次数:13 
求助将循环简化为无限循环
        sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where parent is null or trim(parent)='' order by dwcd"
        cur.execute(sql)
        tr0=cur.fetchall()
        for s0 in tr0:
            root= QTreeWidgetItem(self.tree)
            root.setText(0,s0[0])
            root.setText(1,s0[1])
            dwh=s0[1]
            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
            cur.execute(sql)
            tr1=cur.fetchall()
            if bool(tr1):
                for s1 in tr1:
                    child = QTreeWidgetItem(root)
                    child.setText(0, s1[0])
                    child.setText(1, s1[1])
                    dwh = s1[1]
                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                    cur.execute(sql)
                    tr2=cur.fetchall()
                    if bool(tr2):
                        for s2 in tr2:
                            child2 = QTreeWidgetItem(child)
                            child2.setText(0, s2[0])
                            child2.setText(1, s2[1])
                            dwh= s2[1]
                            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                            cur.execute(sql)
                            tr3=cur.fetchall()
                            if bool(tr3):
                                for s3 in tr3:
                                    child3 = QTreeWidgetItem(child2)
                                    child3.setText(0, s3[0])
                                    child3.setText(1, s3[1])
                                    dwh= s3[1]
                                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                    cur.execute(sql)
                                    tr4=cur.fetchall()
                                    if bool(tr4):
                                        for s4 in tr4:
                                            child4 = QTreeWidgetItem(child3)
                                            child4.setText(0, s4[0])
                                            child4.setText(1, s4[1])
                                            dwh= s4[1]
                                            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                            cur.execute(sql)
                                            tr5=cur.fetchall()
                                            if bool(tr5):
                                                for s5 in tr5:
                                                    child5 = QTreeWidgetItem(child4)
                                                    child5.setText(0, s5[0])
                                                    child5.setText(1, s5[1])
                                                    dwh= s5[1]
                                                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                                    cur.execute(sql)
                                                    tr6=cur.fetchall()
                                                    if bool(tr6):
                                                        for s6 in tr6:
                                                            child6 = QTreeWidgetItem(child5)
                                                            child6.setText(0, s6[0])
                                                            child6.setText(1, s6[1])
搜索更多相关主题的帖子: execute parent sql order trim 
2023-04-02 13:45
东海ECS
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:Python
等 级:版主
威 望:32
帖 子:412
专家分:1646
注 册:2023-1-24
收藏
得分:0 
无限循环:
while True:
    循环体


会当凌绝顶,一览众山小.
2023-04-02 16:42
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
回复 2楼 东海ECS
老师能不能具体一点?谢谢!
2023-04-02 18:42
东海ECS
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:Python
等 级:版主
威 望:32
帖 子:412
专家分:1646
注 册:2023-1-24
收藏
得分:0 
也就是说,把你想要死循环的语句块前面加上
while True:

再缩进即可

会当凌绝顶,一览众山小.
2023-04-02 19:10
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
回复 4楼 东海ECS
我还是不太会弄,辛苦老师给列下代码呗?谢谢!谢谢!
2023-04-02 19:20
东海ECS
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:Python
等 级:版主
威 望:32
帖 子:412
专家分:1646
注 册:2023-1-24
收藏
得分:10 
以下是引用yll148在2023-4-2 19:20:31的发言:

我还是不太会弄,辛苦老师给列下代码呗?谢谢!谢谢!

您想要怎么无限循环?

会当凌绝顶,一览众山小.
2023-04-02 20:34
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
回复 5楼 yll148
说一说你想实现啥功能,无限循环,用户就无法干预了
你不会是想写gui

DO IT YOURSELF !
2023-04-03 07:05
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
回复 7楼 wp231957
谢谢教师回复,我的想法是TREE层次不受限,有多少个层级就延伸到多少层级,直到都没有子集就结束。
2023-04-03 07:39
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
回复 8楼 yll148
这需要递归,不是循环

DO IT YOURSELF !
2023-04-03 09:40
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
回复 9楼 wp231957
谢谢您的回复,能新辛苦老师帮助解决一下吗?
2023-04-03 09:54
快速回复:求助将循环简化为无限循环
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.077333 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved