-1

I'm doing updates to other modules imported in my main file, and I can reload them on the fly in the console and get the new behaviour immediately via

import importlib
importlib.reload(module_name)

How can I do this for the main file?

I tried __name__ but did not work.

PS: I have gigantic datasets and I hate running again the main file after tiny changes, takes forever.

Alex Deft
  • 2,531
  • 1
  • 19
  • 34

1 Answers1

0

You should put your code in the main file into a main function and add this to the end:

if __name__ == "__main__":
    main()

This will let you reload the module while also letting you run it normally. However, after you reload, you have to call module.main().

SuperStormer
  • 4,997
  • 5
  • 25
  • 35