3 ms·
In the refactoring section, it says: Note that if you don’t have if __name__ == '__main__', the code won’t run anything since the function is initialized
by kd5bjo 9y ago
In the refactoring section, it says:
Note that if you don’t have if __name__ == '__main__',
the code won’t run anything since the function is
initialized but not executed
Isn't this backwards? That test isn't required to make the code run, it prevents the code from running if the file is imported as a module.
- cup-of-tea 9y agoYeah, it's written slightly badly, but it means if you don't include that block then nothing will run. The way it's written makes it seem like using the ifmain construct isn't optional, which isn't a terrible thing to teach.