Skip to content

Instantly share code, notes, and snippets.

@tylernchls
Last active January 2, 2018 23:09
Show Gist options
  • Save tylernchls/c567ba207510ac9711740879ee7db338 to your computer and use it in GitHub Desktop.
Save tylernchls/c567ba207510ac9711740879ee7db338 to your computer and use it in GitHub Desktop.

Python Programming Tips

  1. Use python dictionaries when storing data.
  2. INDENTATION, INDENTATION, INDENTATION.
    • Be knowledgable how your environment is set up whether using spaces or tabs. Keep it consistant and also be aware of which version you are using since they will interpret them differently. Example, Python 2 converts tabs as if they were 8-space tabs. Python 3 will just refuse to compile a file that contains a mixture of the two.
  3. Naming convention is key. (I like PEP 8)
    • Name functions, variables... so they have meaning in your code.
    • Variables, functions, methods, packages, module lower_case_with_underscores
    • Classes and Exceptions CapWords
    • Protected methods and internal functions _single_leading_underscore(self, ...)
    • Private Methods __double_leading_underscore(self, ...)
    • Constants ALL_CAPS_WITH_UNDERSCORES
  4. Put all imports at top of your code.
  5. Put comments in your code so you can come back to it later.
  6. Use functions when at all possible.
    • Each function should only do one job.
    • Use to modulize your code.
    • Should take no more than 3 parameters.
  7. Modules from modu import blah
  8. Testing, testing, testing.
    • Write tests to make sure your application is working properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment