(Oct-14-2019, 12:45 PM)ichabod801 Wrote:(Oct-14-2019, 12:23 PM)PyNovice Wrote: Ive just tried it this way
No, you didn't try it that way. What I suggested was this:
def foo(): print(bar) if __name__ == '__main__': foo()That way has the function definition is outside the if __name__ block, and the function call is inside of it. You did this:
if __name__ == '__main__': def foo(): print(bar) foo()You did the exact opposite. You put the function definition inside the if __name__ block, and the function call outside of it.
Whatever you put in the if __name__ block will NOT run when imported. At all. In any form. Ever. So in your version, when you import the code, the function is never defined. Then you try to call a function you didn't define, which necessarily causes an error.
Ive since corrected it. Read post 12
Heres a link to the updated files https://1drv.ms/u/s!AgNGJplI2Q3rgYhtqQ8o...A?e=qC2tyj