Reputation: 361
I want to use the global variables in and outside of the function, but there is an error with calling usingDesired
in the print statements
def getTargetPage():
global usingDesired
global usingNotChecked
while True:
desiredPages = open(r'C:\Users\tree3\Desktop\Instagram\desired_pages.txt', "r")
pagesNotChecked = open(r'C:\Users\tree3\Desktop\Instagram\pages_not_checked.txt', "r")
if os.path.getsize(r'C:\Users\tree3\Desktop\Instagram\pages_not_checked.txt') == 0:
fileReader = open(r'C:\Users\tree3\Desktop\Instagram\desired_pages.txt', "r")
usingDesired = True
if os.path.getsize(r'C:\Users\tree3\Desktop\Instagram\pages_not_checked.txt') > 0:
fileReader = open(r'C:\Users\tree3\Desktop\Instagram\pages_not_checked.txt', "r")
usingNotChecked = True
print(usingDesired)
print(usingNotChecked)
Upvotes: 0
Views: 49
Reputation: 69
declare a variable usingDesired globally without global keyword. Inside function you can manipulate this variable as below
global usingDesired
usingDesired = 'udpate global variable value'
Upvotes: 1