Created
September 30, 2018 17:59
-
-
Save ianfoo/47b115a3a2b78345fd319643d74dbfaf to your computer and use it in GitHub Desktop.
Simple example of defining and using Python modules
This file contains hidden or 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
| def dishroom(): | |
| return "Dishroom has 24 hour beans." | |
| def huh(): | |
| return "You cooked beans for 24 hours? What's the matter with you?" | |
| def sports(): | |
| return "¯\_(ツ)_/¯ Let's go watch sports." |
This file contains hidden or 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
| class Foo: | |
| def __init__(self, message): | |
| self.message = message | |
| def say(self): | |
| return self.message | |
This file contains hidden or 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
| def status(): | |
| return "Luca is okay!" |
This file contains hidden or 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
| from bar import dishroom, huh, sports | |
| from foo import Foo | |
| from residents import luca | |
| def main(): | |
| foo = [ Foo(luca.status()), | |
| Foo(dishroom()), | |
| Foo(huh()), | |
| Foo(sports()) ] | |
| for f in foo: | |
| print(f.say()) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment