[Tutor] How the shell relates to programs in idle

DL Neil PyTutor at DancesWithMice.info
Tue Feb 25 18:35:11 EST 2020


On 26/02/20 3:48 AM, daniel rieder wrote:
...

> 
> def main():
> 
>      dictionary = createDictionary()
> 
>      print(dictionary['two'])
> 
>      print(dictionary['red'])
> 
> 
> 
> main()

...

Further to earlier explanation (and slightly wary because I don't use 
Idle), instead of declaring a main function, consider another common 
Python idiom:

if __name__ == "__main__":
     dictionary = createDictionary()
     print(dictionary['two'])
     print(dictionary['red'])

(should) continue to work, plus leave access to dictionary thereafter.


WebRef: https://docs.python.org/3/library/__main__.html
-- 
Regards =dn


More information about the Tutor mailing list