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.
Python tutorials and tricks, concepts and exploring cool modules with extensive examples.
Search
Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts
25 June, 2018
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.
29 May, 2018
SVN commands you must know as an Test Automation Engineer
In the course of automation and continuous integration , you will someday come across a stage where you have to perform svn operations . And obviously, using command line (forget fancy UIs to do your business) using command line. And then you will have to start digging in, which will take a substantial amount time ...believe me.
25 May, 2018
How to use argparse module to create command line tools with Python?
Its been decades I have been using sys.argv for simple tasks related to argument parsing. But the thing is, sometimes we don't realize how good something is unless we use it . Like the argparse module.
The official document got me totally confused. So I wrote my own tutorial. Let's get started.
02 May, 2018
Exploring COLLECTIONS module from Python
The 'collections' module has some interesting methods that give us an edge over generic inbuilt tools . I want to explore them here today and show how you can use them .
namedtuple
Tuples are represented as (item1, item2, item2, ...) . They support indexing and one of the ways to use them is :
>>> from collections import namedtuple >>> Car = namedtuple('Car','Price Mileage Colour Class') >>> xyz = Car(Price = 100000, Mileage = 30, Colour = 'Cyan', Class = 'Y') >>> print xyz Car(Price=100000, Mileage=30, Colour='Cyan', Class='Y') >>> print xyz.Class Y
They turn tuples into convenient containers for simple tasks. With namedtuples, you don’t have to use integer indices for accessing members of a tuple.
16 March, 2018
How to use Docker with Python projects
Docker is the modern way to share ready made machines , so other can use it without the usual hassles of configuration and environment setup. I wanted to try it myself first hand, to see what the fuss is about. I want to share what I found, so you start your project right now.
Before we start, for the absolute beginners who ABSOLUTELY NO IDEA about DOCKER, let me try to explain what it is:
Dockers are the new generation Virtual Machines which totally remove the need to install another files on a system just to run or test something . They are just CONTAINERS with all the things necessary for our app to work. That's it .
Before we start, for the absolute beginners who ABSOLUTELY NO IDEA about DOCKER, let me try to explain what it is:
It is a CONTAINER which CONTAINS ALL that you NEED to run your project.
08 March, 2018
Testing GET and POST calls using Flask
I was trying out Flask. In the process, I made a website that behaves like a server. It can help you test GET and POST calls.
It goes like this .
from flask import Flask, request app = Flask(__name__) @app.route('/method', methods=['GET', 'POST']) @app.route('/method/<wish>', methods=['GET', 'POST']) def method_used(wish=None): if request.method == 'GET': if wish: if wish in dir(request): ans = None s = "ans = str(request.%s)" % wish exec s return ans else: return 'This wish is not available. The following are the available wishes: %s' % [method for method in dir(request) if '_' not in method] else: return 'This is just a GET method' else: return "You are using POST"
05 March, 2018
Why should we use Class in Python ?
Lots of people ask me, why should they use classes at all ? Well. I think its about control, and ease . It solves the headache of data sharing and accessibility. I am going to show you an example , which hopefully proves that classes and fundamentals like inheritance are brilliant.
Example:
I have two classes in the below program. Person and Manager . Manager has inherited the Person class (because he is a person too....almost (lol)) .
11 February, 2018
Python Decorators with simple examples
Everyone who has used python , has sooner or later come across decorators . That's that thing sitting on a function which magically does something special . It looks like :
@mydecorator
def my_function
Today we are going to learn , how to write decorators of our own . How this works:
14 January, 2018
How to run a Python program on the internet from anywhere?
I want to run a python program whenever I need and get some
information out of it. The problem is, I want to call that through internet.
And I want to show the content on a web page or some UI container. That's it. Let
put this as a requirement.
Problem: Display some information on
my web page calculated by a python program
I want to run a python program whenever I need and get some
information out of it. The problem is, I want to call that through internet.
And I want to show the content on a web page or some UI container. That's it. Let
put this as a requirement.
How do we do it on our
local computer? We run our program as : python my_program.py.
So maybe I can do
something like: www.mywebsite.com/my_program.py . Can we? No
idea.
I expect to collect the response in some variable (no idea how I can create a variable in the first place on html) and then display the contents of this variable. Displaying a simple text on html is known, so that should be easy.
Subscribe to:
Posts (Atom)