How to fix TypeError: 'int' object is not callable from a divided number

How to fix TypeError: 'int' object is not callable from a divided number

我试图创建一个程序来从 txt 文件中生成带有用户名的文本,但我一直收到 TypeError: 'int' object is not iterable 我知道这意味着什么,但我不知道如何解决我的问题。我尝试只做 y = 12 / 2,当我通过 for 循环时出现了同样的错误 y 我真的很困惑所以如果有人能帮助我那会很棒

这是我的代码

def generateNum():
        #imports random
        from random import randint

        for _ in range(10):
            value = randint(0, 900000)
            return(str(value))

def getNumOfLines( file):
        #opens txt file
        with open(file) as f:
            Lines = f.readlines()
            count = 0
            # Strips the newline character
            for line in Lines:
                count += 1

            return(count)
class debug:
    def __init__(self, credsTxt, tagsTxt):
        self.credsTxt = credsTxt
        self.tagsTxt = tagsTxt

        self.numOfCreds = getNumOfLines(credsTxt)
        self.numOfTags = getNumOfLines(tagsTxt) 

        self.ammountPerAccount = round(self.numOfTags / self.numOfCreds)   

    
    def getComments(self):
        #initializes comment
        comment = ""
        #opens txt file

        file1 = open(self.tagsTxt, 'r')

        count = 0
        while True:
            count += 1
        
            # Get next line from file
            line = file1.readline()

            for i in self.ammountPerAccount:
                # if line is empty
                # end of file is reached
                if not line:
                    break
                comment += ' ' + line.strip() + ' ' + generateNum() + '.'  
            return(comment)
                


print(debug('D:/FiverrWork/user/instagram-bot/textGen/assets/login_Info.txt', 'D:/FiverrWork/user/instagram-bot/textGen/assets/tags.txt').getComments())

这是我的堆栈跟踪错误

Traceback (most recent call last):
  File "d:\FiverrWork\user\textgenerator\textgenerator\txt.py", line 57, in <module>
    print(debug('D:/FiverrWork/user/textgenerator/textgenerator/assets/login_Info.txt', 'D:/FiverrWork/user/textgenerator/textgenerator/assets/tags.txt').getComments())
  File "d:\FiverrWork\user\textgenerator\textgenerator\txt.py", line 47, in getComments
    for i in self.ammountPerAccount():
TypeError: 'int' object is not callable

您发布的 for 循环无法遍历 int。您打算遍历 range():

for _ in range(self.ammountPerAccount):

    # if line is empty
    # end of file is reached
    if not line:
        break
    comment += ' ' + line.strip() + ' ' + generateNum() + '.' 

我使用 _ 作为占位符变量,因为每次 i 的实际值都没有被使用。