如何连续加+1反击?

How to add +1 continuously to counter?

这可能是一个愚蠢的问题,但这里没有任何意义:

我的计数器从 2821614688517316738 开始。

如何为每次迭代将每个加 1?

counter = 2821614688517316738
counter += 1
print(counter)

输出:

2821614688517316739
2821614688517316739
2821614688517316739

如何连续给它加1,而不是恢复到原来的计数器数?

有些人要求完整的代码,就在这里。

简要说明它经过了 3954 个文档。它连接到一个 API,它要求计数器为每次迭代或发送到 API 的请求 +1。

from bs4 import BeautifulSoup
import xml.etree.ElementTree as ET
import glob
import os
import hashlib 
import hmac 
import requests 
import json
import pandas as pd
from pandas.io.json import json_normalize


path = "/Users/User/Downloads/Thesis papers/links/"
for filename in glob.glob(os.path.join(path, "*")):
    with open(filename) as open_file:
        content = open_file.read()

    bs = BeautifulSoup(content, "xml")
    for individual_xml in bs.find_all("Response"):
        for link in individual_xml.find_all("Fields"):
            for fields in link.find_all("Field"):
                word = "Earnings Call"
                if word in fields["value"]:

                    for i in link.find_all("Field", {"id":"7011"}):
                        #print(fields)
                        #print(i["value"][0])


                        #Your FactSet Information  
                        key = ' *' #Insert Key from auth-factset.com 
                        keyId = '*' #Insert KeyID from auth-factset.com 
                        username = '*'  #Insert your FactSet Username provided by your FactSet Account team 
                        serial = '*' #Insert Serial Number tied to machine account provided by your FactSet Account 
                        counter = 2821614688517316742
                        for gg in range(counter):
                            counter += 1
                            print(counter)
                            ba_key = bytearray.fromhex(key) 
                            my_int = counter.to_bytes(8, 'big', signed=True) 
                            my_hmac = hmac.new(ba_key,msg=my_int, digestmod=hashlib.sha512) 
                            digested_counter = my_hmac.digest() 
                            otp = digested_counter.hex()
                            json_object = {     
                                    'username': username,     
                                    'keyId': keyId,     
                                    'otp': otp ,     
                                    'serial': serial 
                                    }
                            OTP_url = 'https://auth.factset.com/fetchotpv1' 
                            payload = json.dumps(json_object) 
                            header = {'Content-Type': 'application/json'} 
                            r = requests.post(OTP_url, data=payload)   
                            r_key = r.headers.get(key='X-DataDirect-Request-Key')
                            r_token = r.headers.get(key='X-Fds-Auth-Token') 
                            print('DataDirect Request Key: ', r_key) 
                            print('Token:', r_token) 
                            #Confirm authentication and session token work 
                            header = {'X-Fds-Auth-Token':r_token}  
                            Service_url = 'https://datadirect.factset.com/services/auth-test'
                            r = requests.get(Service_url,headers=header) 
                            url = i["value"]
                            r = requests.get(url,headers=header)
                              #bs = BeautifulSoup(r, "xml")

                            #print(r.text)
                            with open(''+fields["value"]+''+'.xml', 'w') as f:
                                f.write(r.text)

简单回答:

counter = 2821614688517316740
while True:
    counter += 1
    print(counter)

请注意这是一个无限循环...

编辑

I know the exact number of iterations required, it is 3954, can we set this as a limit somehow? –

当然可以。

counter = 2821614688517316740
for _ in range(3954):
    counter += 1
    print(counter)

现在我可以建议你做完整的 official Python tutorial 吗?

它会遍历计数器并在其中不断添加一个数字

counter = 2821614688517316738
for i in range(3954):
    counter += 1
    print(counter)