Skip to content

Instantly share code, notes, and snippets.

@edoput
Created August 10, 2020 08:23
Show Gist options
  • Save edoput/e154f85aa39a45ee9754d42d58176736 to your computer and use it in GitHub Desktop.
Save edoput/e154f85aa39a45ee9754d42d58176736 to your computer and use it in GitHub Desktop.
example of modules and scripting
# 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)
# 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