Home > Software engineering >  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

Time:04-10

Im trying to create a program to generate text with usernames from a txt file but I keep getting a TypeError: 'int' object is not iterable i know what this means but I have no idea how to fix my issue. I tried just doing y = 12 / 2 and the same error came up when i passed the for loop y i am really confused so if someone could help me that would be great

This is my code

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())

this is my stack trace error

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

CodePudding user response:

Your for loop as posted cannot iterate over an int. You meant to iterate over a range():

for _ in range(self.ammountPerAccount):

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

I used _ as a placeholder variable since the actual value of i each time was not used.

  • Related