'Get a variable from a function using import in python

Here is the main.py file:

from index import count, mainFunction
mainFunction()
print(count)

index.py:

count = 0

def mainFunction():
    global count
    for i in range(10):
        count+=1

My problem is that I want to import the count variable after the mainFunction() has been called. The count variable is 0 by default, it gets modified in the mainFunction()



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source