Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
Last active October 20, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathunstrom/ceca1fdf24250d256133c83cfc56c876 to your computer and use it in GitHub Desktop.
Save pathunstrom/ceca1fdf24250d256133c83cfc56c876 to your computer and use it in GitHub Desktop.
Organize python code
"""Everything should be alphabetical in it's group."""
# Group imports by where they come from
# Standard Lib
import os
# PyPI/third party
import requests
# Local
import my_script
# Classes at the top
class AClass:
pass
class BClass:
pass
# Functions at the bottom
def a_func():
pass
def a_wrapper(func):
def the_wrapper():
return func()
def b_func():
pass
def main():
a_func()
b_func()
z_func()
@a_wrapper
def z_func():
pass
# If you're making your script executable, this goes last.
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment