Reputation: 10855
I have a python script in which there is a line:
if __name__ == "__main__":
...
So how can I run this portion of the code in another script after importing the script above?
Thanks.
Upvotes: 0
Views: 86
Reputation: 4114
Make it an independent function.
def run_main():
....
if __name__ == "__main__":
run_main()
And you can call run_main()
from another file.
Upvotes: 10