The goal is , to call a FLASK route without reloading the page, when a button is pressed. The content of a div must change with the response text received from the flask route call.
Python tutorials and tricks, concepts and exploring cool modules with extensive examples.
Search
14 August, 2018
13 August, 2018
How to use Python unit test module and it's methods?
Unit test module is an in-build library in python, used to write test scripts . It gives some helpful methods while helps us designing out test in a way , that emulates a real production environment.
While writing test, we need to keep these things in mind
1. Test should start with a clean slate. Meaning the subject under test must not hold any info or be in a state, that might affect the test results.
2. Every tests should test one and only one feature . Clubbing multiple tests in one test, is a bad idea.
Unit test provides some special methods. These can be used to handle the flow of tests as per scenario. Below is a generic template of a unit test showing all methods and their tasks.
While writing test, we need to keep these things in mind
1. Test should start with a clean slate. Meaning the subject under test must not hold any info or be in a state, that might affect the test results.
2. Every tests should test one and only one feature . Clubbing multiple tests in one test, is a bad idea.
Unit test provides some special methods. These can be used to handle the flow of tests as per scenario. Below is a generic template of a unit test showing all methods and their tasks.
16 July, 2018
Generator functions. Why and when should we use them.
You probably have heard of them. But as a beginner python programmer, we tend to ignore it's values because we fail to find uses of it. When we have loops and itertools and other fancy toys offered, why should we bother to understand them. If you want to take your programming or understanding of Python to the next level, you must understand and use generators more and more.
25 June, 2018
How to test POST call using Python?
I got into a situation recently where I needed to test if my POST function was indeed working.
Its easy to test GET method . You just visit the URL and that's it . But for POST, you an use Plugins. But unfortunately I can't do that , because my browser (admin restrictions ) doesn't allow me to install plugins . Fortunately if you have Python , you can easily do that .
How to work on a Python Project when modules versions needed are different? Use virtualenv
Gone are the days when you need to create a VM for working on a different set of tools. People work on different projects which might need a special version of a module. (Or python itself) . The problem aggravates when multiple users work on a single shared machine (Test environments or Build machines ) .Virtual Environments help solve problem . And its easy to use and share among fellow teammates.
12 June, 2018
Exploring Numpy
What can we really do with Numpy? Why should we use it at all ?
Start with : import numpy
method: numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)
In the above array, there are 10 columns and 1 row.
Note : The concept of rows and columns applies when you have a 2D array. However, the array
Refer this link.
Start with : import numpy
1. We can create arrays .
method: numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)
>>> a = numpy.array(range(10)) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> a.dtype dtype('int32')
In the above array, there are 10 columns and 1 row.
Note : The concept of rows and columns applies when you have a 2D array. However, the array
numpy.array([1,2,3,4])
is a 1D array and so has only one dimension, therefore shape
rightly returns a single valued iterable.Refer this link.
01 June, 2018
Python List sorting with key argument explored
Everybody uses lists as an array to store values. List provide a lot of in-build features.
- Sorting
- Membership
- Indexing
- Iteration
- reversing
- Adding/Removing
- Popping
- Count
Lots of reasons to use lists. I think, one of the most used features is sorting. Internally , python uses Merge sort technique to sort the array items. But the sort method can be used in many other ways to have more control.
Subscribe to:
Posts (Atom)