Why is my python3 function running without being called?

Question:

Using python3.8 on macOS

I have a function with a while loop inside, and i also import two other .py files from the same directory which contain functions i need.

import Scraper
import Creator

def main(index=1):
    operation = True
    while operation == True:
        try:
            Scraper.scraper()
            Creator.Auto(index)

        except Exception as e:
            print(e)
            operation = False

    return

Without calling main(), if i run my program it will still run the main() function. This also happens when i call main(), the program will then run using the while loop, but only after running through the function once before the while loop begins. (ie: the function will run one more time than expected)

I havent encountered a problem like this before. Any tips on fixing this?

Asked By: Gablo Ficazzo

||

Answers:

Try to check other .py files. Once I had the same problem when my other .py files contained calls of the functions. When you import .py file and it contains call of the function, this function can be called automatically.

Answered By: kot.shubin