Python Import Modules


This is actually really simple, so if you have another python file, you can import it to use the code by declaring import and the path to the file without .py since it’s assumed.

This also comes with this nifty thing called __main__ which is going to be the file that is running, so if you had code, maybe for testing that you wanted to only run when you are running that specific file, but not when you are using it via an import in another file.

if __name__ == '__main__':
     test()

that would be a condition to check.


Leave a Reply

Test Your email address will not be published. Required fields are marked *