Created
August 10, 2020 08:23
-
-
Save edoput/e154f85aa39a45ee9754d42d58176736 to your computer and use it in GitHub Desktop.
example of modules and scripting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this part is executed when you load it | |
a = 0 | |
while a < 10: | |
a++ | |
# now we could have executed whatever here, read a file | |
# reboot the system, not so nice and the reason you | |
# should read a dependency to make sure you are not | |
# going to kill yourself | |
def fetch(): | |
return a # a is 10 | |
if __name__ == '__main__': | |
# this is a conditional execution | |
# if you run python data.py it gets | |
# executed | |
print(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# we are importing the names in data.py into | |
# our environment, what happens next is that | |
# the file data.py gets interepreted and we | |
# bind the name fetch from that module to the | |
# name fetch in this module | |
from data import fetch # as my_fetch # this would bind fetch to another name | |
if __name__ == '__main__': | |
d = fetch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment