I have declared a few variables and initialised them with some value in variables.py
Contents of variables.py :
flag = 0
j = 1
if(flag == 0) :
j = j+1
NameError: name 'flag' is not defined
Everything you've done is right except when using the variables.
In your main_file.py file:
if(variables.flag == 0) : variables.j = variables.j + 1
Use the following header :
from variables import *
from variables import flag, j
Replace all the references of flag and j (or any other variable you want to use from that file) with the prefix 'variables.'
Since this is just a copy of the variable, the values in the variables.py won't get affected if you modify them in main_file.py