I have a program that writes a separate in order to make a series of similar functions. These functions are to call another function, checkbuy, from the main source code. Whenever I try this, it says it's not defined. Globalizing the main function in the module functions fails.
Module function:
def buyMagikarp():
global pokenums
if checkbuy(10,1): #calling the function from main file
pokenums['Magikarp']+=1
Magikarp.config(text='Magikarp: '+str(pokenums['Magikarp']))
This function is used inside of a Tkinter Button object, and is successfully called when the button is clicked.
Function in main:
def checkbuy(price,amount):
global coin, coingainnum
if coin >= price:
coin-=price
updatecoin()
coingainnum+=amount
return True
else:
return False
Module function works in works when in main.
How to call function from function in local namespace?
mainalready imports the module, so you can't also importmainfrom the module because that would be circular. I would movecheckbuyto another module (libor something more descriptive), which you can then import in bothmainand the other modulescheckbuyto be in scope in the other module?