免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2548 | 回复: 1
打印 上一主题 下一主题

python 函数为什么需要执行多次才能获取完整数据 [复制链接]

论坛徽章:
3
黄金圣斗士
日期:2015-12-01 13:27:34IT运维版块每日发帖之星
日期:2016-04-30 06:20:0015-16赛季CBA联赛之福建
日期:2018-08-10 14:38:43
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2017-10-19 11:25 |只看该作者 |倒序浏览
  1. from manage import app
  2. from thunderops.tables import Dept,User

  3. ctx = app.test_request_context()
  4. ctx.push()
  5. dept=Dept.query.filter_by(id=96).first()
  6. listuser=dept.Dept_ref
  7. def get_user(dept,listuser):
  8.     cdepts=Dept.query.filter_by(parentid=dept.id).all()
  9.     for d in cdepts:
  10.         listuser+=d.Dept_ref
  11.         get_user(d,listuser)
  12.     return listuser
  13. print get_user(dept,listuser),len(listuser) ###第一次长度是11
  14. print get_user(dept,listuser),len(listuser) ###第二次长度是16
  15. ctx.pop()
复制代码
请问这是甚么情况

论坛徽章:
3
黄金圣斗士
日期:2015-12-01 13:27:34IT运维版块每日发帖之星
日期:2016-04-30 06:20:0015-16赛季CBA联赛之福建
日期:2018-08-10 14:38:43
2 [报告]
发表于 2017-10-19 13:23 |只看该作者
测试应该是表关系d.Dept_ref 这个一对多的问题 ,直接查询是没问题的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP