Wilson Mar bio photo

Wilson Mar

Hello. Hire me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Instagram Youtube

Github Stackoverflow Pinterest

Tricks and tips from learning resources


Overview

Here are various coding tips I’ve seen while going through Python programming classes after installing Python and Juypter.

Dan Bader has emails and courses on Python: VIDEO What Python Projects Should I Build to Get a Job? Aug 23, 2017

  1. tensorflow (for machine learning)
  2. crawling (spider based projects)
  3. database handling (firebase, Mysql etc.)

  • Object-oriented programming with classes and their methods
  • Cloud Python

Command generator

docopt at https://github.com/docopt/docopt and described at http://docopt.org/ creates custom CLI commands by parsing a command help text into cli code that implements it.

Brilliant.

Click

Dan Bader recommends the use of the

http://click.pocoo.org/6/why/ click custom package (from Armin Ronacher) instead of the argparse package that comes with Python 3.2+ (and the optparse package that comes with Python 2).

Click provides decorators such as the “@click.command()” below:

\# cli.py
import click

@click.command()
def main():
    print("I'm a beautiful CLI ✨")

if __name__ == "__main__":
    main()
   

List comprehension

squares = [x * x for x in range(10)]

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

The Playbook of code shown on What Does It Take To Be An Expert At Python? [1:52:02] presented by by James Powell at the PyData conference on Aug 2, 2017.

Abhishake Gupta’s pyTest https://github.com/letspython3x/code_examples

https://www.codementor.io/alibabacloud/how-to-create-and-deploy-a-pre-trained-word2vec-deep-learning-rest-api-oekpbfqpj

https://www.learnpython.org/en/Classes_and_Objects

Testing

Pros create a test .py file to go with each py file.

There are several libraries to support testing.

  1. unittest

    Described at Python Tutorial: Unit Testing Your Code with the unittest Module Aug 16, 2017 by Corey Schafer

  2. pyTest

    • after pip3 install pytest
    import file_ab_session as fas
    def test_add_function_given_two_arguments():
     RESULT = fas.add(2,3)
     EXPECTED_RESULT = 5
     assert RESULT == EXPECTED_RESULT
    

Applicable to both:

  • Name all test classes with a name beginning with “test”.

  • Tests are not run from top to bottom, so each test needs to be stand-alone.

  • To do stuff before the tests:

   @classmethod
   def setupClass(cls)
       print('in setupClass')

   @classmethod
   def tearDownClass(cls)
       print('in tearDownClass')
   

mocking

Mocks

Python in the Cloud

On AWS:

On Azure:

pip install azure
  • https://docs.microsoft.com/python/azure/
  • https://azure.microsoft.com/resources/samples/?platform=python
  • https://github.com/Azure/azure-sdk-for-python/wiki/Contributing-to-the-tests
  • https://azure.microsoft.com/en-us/support/community/

More about Python

Also see Python REST API programming. Python Robot testing. Running Python on Raspberry Pi IoT devices.