Python 帮忙看下这个为什么进不到循环。求助

路小圣 · 2019年02月28日 · 最后由 路小圣 回复于 2019年02月28日 · 1514 次阅读

创造测试数据,但是一直进不去循环不知道为什么?

 #!/usr/bin/python
 # coding:utf-8
 # author:hutong


import time
# 构造表pms_parking_info
def park():
    start = time.time()
    # 定义需要生成的数据量
    count = 10  # 1万
    beginID = 666
    try:
        with open("/Users/zln/user.txt", "wb") as fo:
            length = count + 1
            for i in range(49, length):
                while i>=49:
                    id=str(i+1)
                while beginID>=666:
                    thirdParkId=str(beginID+i)
                tenantId = 13
                areaId = 91
                pathCode = '0001.0001.0001'
                aliParkId = '#'
                thirdSourceType = 0
                code = 140128443739145215
                localCode = '#'
                dockId = '#'
                name = 'JOJOJO'
                fullName = 'jiojiodsaaa'
                status = 1
                platformSupport = 1
                level = 0
                chargeFee = 1
                supportAppointment = 0
                outTime = 1
                type = 1, 2, 3
                lotType = 1
                logo = "http"
                openStartTime = '00:00'
                openEndTime = '23:59'
                chargeMode = 2
                payMode = 1
                payType = 1
                latitude = 30.068776
                longitude = 119.939741
                provinceCode = 110000
                cityCode = 110100
                countyCode = 110101
                address = '12'
                lotTotal = 200
                lotFixed = 0
                description = '#'
                auditStatus = 2
                auditUserId = 1
                auditUserName = 'administrator'
                runStatus = '4'
                creatorUserId = 73
                creationTime = '2019-02-06 11:32:02'
                lastModifierUserId = '2019-02-26 11:32:02'
                lastModificationTime = '2019-02-27 16:21:42'
                deleterUserId = 'null'
                deletionTime = 'null'
                deleted = 0
                version = 1
                freeTime = 15
                pms_parking_info = (
                    "INSERT INTO 'xcp_cloud'.'pms_parking_info' VALUES ('%s', '%s', '%s','%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',);"
                    % (id, tenantId, areaId, pathCode, aliParkId, thirdSourceType, thirdParkId, code, localCode, dockId, name, fullName, status, platformSupport, level, chargeFee, supportAppointment, outTime, type, lotType, logo, openStartTime, openEndTime, chargeMode, payMode, payType, latitude, longitude, provinceCode, cityCode, countyCode, address, lotTotal, lotFixed, description, auditStatus, auditUserId, auditUserName, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), runStatus, creatorUserId, creationTime, lastModifierUserId, lastModificationTime, deleterUserId, deletionTime, deleted, version, freeTime)
                )
                pms_parking_info = pms_parking_info + '\n'
                fo.write(pms_parking_info.encode('UTF-8'))
            print('共创建1万条sql耗时:', time.time() - start)
    except Exception as e:
        print(Exception, ":", e)
    if __name__ == "__main__":
        park()

共收到 5 条回复 时间 点赞

首先声明我并不是什么大神,我这个人比较笨哈,没看懂你这个具体要干嘛,但是你这句
length = count + 1
for i in range(49, length):
while i>=49:
length 应该是 11 对吧

count = 10  # 1万
    beginID = 666
    try:
        with open("/Users/zln/user.txt", "wb") as fo:
            length = count + 1
            for i in range(49, length):

这里的逻辑有问题吧? length = 10+1 ,也就是 11; 然后 for i in range(49,11) 没有满足条件的 i ,所以进不去这个循环。

for i in range(49, length),第一次 length 是 11, i 没有可取的值呀

解决办法:建议把 count = 10 # 1 万,10 换成 10000 试下

while i>=49:
      id=str(i+1)
while beginID>=666:
      thirdParkId=str(beginID+i)

另外看不懂这两段 while 的作用, 如果 i 和 beginID 满足条件,是会死循环跳不出去的吧? 感觉上你是不是想用 if ?

循环错了 底部的 main 方法 if 前面有空格。。解决了多谢各位

路小圣 关闭了讨论 02月28日 16:09
需要 登录 後方可回應,如果你還沒有帳號按這裡 注册