There are some sections of python code that we’d like to include that are gated behind the statement: if __name == ‘main’. Because the supervisor script imports and calls our functions it seems these sections won’t run because they aren’t ‘main’. Is there any way to run these sections or do we have to leave them out for the competition?
Hi @robby,
Are these scripts with if __name__ == "__main__"
scripts that you have written? There are a few approaches you might try taking here:
(1) Refactor your code to move whatever logic is in the if __name__ == "__main__"
block is in a function. For example:
# Original
if __name__ == "__main__":
#do stuff
# Refactored
def do_stuff():
# do stuff
...
if __name__ == "__main__":
do_stuff()
This approach lets you call do_stuff()
from inside the predict
or preprocess
functions that we’re asking you to implement. It also still allows you to call your scripts from the command line the original way you’ve been using them.
(2) Use the subprocess
library, e.g., the subprocess.run
function, to call your scripts with a shell command
They’re chunks of code we’ve included within the preprocess function, thanks for the response, I’ll try those out