我正在尝试做一个logtest,我已经做了一个输出,但我有一些东西要补充,但我不能这样做

问题描述 投票:0回答:1

我正在尝试做一个logtest,我已经做了一个输出,但我有一些东西要补充,但我不能这样做

for i in range(int(sys.argv[1]),int(sys.argv[2])):
stdate = parser.parse(sys.argv[3])
todate = parser.parse(sys.argv[4])
while stdate <= todate:
    lctr += 1 
    if lctr == 1:
        if fctr % 100 == 0:
            print('creating sample' + str(fctr).rjust(5,"0") + '.txt')
        f = open("sample" + str(fctr).rjust(5,"0") + '.txt',"w")

    f.write(str(i) + ', ' + stdate.strftime('%m/%d/%Y') + ', 0800, A\r\n')
    f.write(str(i) + ', ' + stdate.strftime('%m/%d/%Y') + ', 1700, Z\r\n')

    stdate = stdate + timedelta(days=1)

    if lctr == 180 :
        fctr += 1
        lctr = 0
        f.close()

这是输出

100001, 02/01/2019, 0800, A
100001, 02/01/2019, 1700, Z
100001, 02/02/2019, 0800, A
100001, 02/02/2019, 1700, Z
100001, 02/03/2019, 0800, A
100001, 02/03/2019, 1700, Z
100002, 02/01/2019, 0800, A
100002, 02/01/2019, 1700, Z
100002, 02/02/2019, 0800, A
100002, 02/02/2019, 1700, Z
100002, 02/03/2019, 0800, A
100002, 02/03/2019, 1700, Z
100003, 02/01/2019, 0800, A
100003, 02/01/2019, 1700, Z
100003, 02/02/2019, 0800, A
100003, 02/02/2019, 1700, Z
100003, 02/03/2019, 0800, A
100003, 02/03/2019, 1700, Z
100004, 02/01/2019, 0800, A
100004, 02/01/2019, 1700, Z
100004, 02/02/2019, 0800, A
100004, 02/02/2019, 1700, Z
100004, 02/03/2019, 0800, A
100004, 02/03/2019, 1700, Z

但这是我想要的输出

100001, 02/01/2019, 0800, A
100001, 02/01/2019, 1700, Z
100001, 02/02/2019, 0800, A
100001, 02/02/2019, 1700, Z
100001, 02/03/2019, 0800, A
100001, 02/03/2019, 1700, Z

100002, 02/01/2019, 0800, A
100002, 02/01/2019, 1700, Z
100002, 02/02/2019, 0800, A
100002, 02/02/2019, 1700, Z
100002, 02/03/2019, 0800, A
100002, 02/03/2019, 1700, Z

100003, 02/01/2019, 0800, A
100003, 02/01/2019, 1700, Z
100003, 02/02/2019, 0800, A
100003, 02/02/2019, 1700, Z
100003, 02/03/2019, 0800, A
100003, 02/03/2019, 1700, Z

100004, 02/01/2019, 0800, A
100004, 02/01/2019, 1700, Z
100004, 02/02/2019, 0800, A
100004, 02/02/2019, 1700, Z
100004, 02/03/2019, 0800, A
100004, 02/03/2019, 1700, Z
python
1个回答
0
投票
flag = None # ---add

for i in range(int(sys.argv[1]),int(sys.argv[2])):
stdate = parser.parse(sys.argv[3])
todate = parser.parse(sys.argv[4])
while stdate <= todate:
    lctr += 1 
    if lctr == 1:
        if fctr % 100 == 0:
            print('creating sample' + str(fctr).rjust(5,"0") + '.txt')
        f = open("sample" + str(fctr).rjust(5,"0") + '.txt',"w")

    f.write(str(i) + ', ' + stdate.strftime('%m/%d/%Y') + ', 0800, A\r\n')
    f.write(str(i) + ', ' + stdate.strftime('%m/%d/%Y') + ', 1700, Z\r\n')

    if flag and flag != str(i):  # ---add
        f.write('\n')            # ---add
    flag = str(i)            # ---add

    stdate = stdate + timedelta(days=1)

    if lctr == 180 :
        fctr += 1
        lctr = 0
        f.close()
© www.soinside.com 2019 - 2024. All rights reserved.