Python Blog Posts

How to use Python in Devops

Python in DevOps
Nowadays everyone is looking at DevOps and Python. So if you want to know why the python is important in DevOps this article may help you.
In DevOps culture, we are required to do a lot of automation using tools and scripts. Python will provide huge open libraries and modules to help in that automation.
If we want to write a script to automate a task Python is a better option in terms of platform independence, easy to write and integrations with all tools. In Python there are so many modules available as open-source which supports several tools.
Below are some useful modules in python to write automation scripts.
Gitapi is a python module which will interact with our version control system, so if you wish to set properties or some useful functions dynamically you can write a python script using this module.
Continuous integration we need to add some scripts to perform some of the jobs. If we write those scripts in bash or PowerShell then we will face a problem when our CI environment is changed. So we can use python to so that we can move our environments.

3 Likes 2280 Views
Basics of Python OS module

OS module provides a lot of functions to interact with Operating System which can handle files, processes and environment paths and many more.
If you are planning to automate some tasks in your server which handle paths, system variables OS module is the best option because of platform independence.
OS module is platform independent, you can write the script in any machine (Linux, Windows etc.) and you can execute the same script for the same functionality in other machines also if the code is not platform independent.
If you want to list down all functions for OS modules you can directly go through the official documentation page of python i.e
Here I will discuss some of the functions which I use most of the time.
For any module in python, the first thing is you need to import it, and you can import os modules as below.
import os

1 Likes 264 Views
working with REST api internet resources with python and python requests

In this article we are going to see how to use python packages/modules to request REST api mostly web services publicly available.
If you are requesting to an URL it should be the one of the type below from CRUD operations.
POST ( Create )
GET ( Read)
PUT ( Update)
DELETE ( Delete)
Lets say you have the API access to your resources through web services and you want to automate some tasks then you can use python requests package.

1 Likes 139 Views

This article helps you to deduplicate a string given a string and chunk size.
Case : Lets say you have a large text file. Each row contains an email id and some other information (say some product-id). Assume there are millions of rows in the file. How would you effieciently de duplicate the data ?
DeDuplication : The process that returns an intermediate strinig , helps in reduplication of original string.
Steps to follow :
1. Break the string into chunks of the given size (Values of chunk size can be 1KB,10KB and so on).
2. Find the unique chunks and make a note of where these chunks occur in the string.
3. The intermediate string should contain the unique strings and their positions.

0 Likes 1842 Views
Django all auth setup from the scratch

When we are implementing any webapplication, we may need to setup the user management for our django application. I wonder if I can get the whole package that will manage all things about Users like Registration, Logins, Social signups etc.
Luckily we got the django application which will do the same i.e django-allauth.
This app will provide so many functionalities as we need ready made. Some of them are listed below.
User Signup of both local social accounts
Email or Username logins
E-mail address management like verification etc.
Recover forgotten password

2 Likes 644 Views
Introduction to Python

What is Python?
Python is a snake and also a name to a computer language which was implemented by Guido van Rossum.
So python is not only a snake anymore it is also a programming language that most of the developers fell in love with it once started using it.
Official documentations says
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
Why Python is that much popular, here are some points.
Python is a simple and reading python programs almost feel like English statements.

0 Likes 171 Views
Install Python and start using it in windows or linux

Install python and start using it
In this series I am going to use python 2.7 version, since most of the systems are still using Python2. Stable Python 3 is released and if you want to start with that also there is no problem. Most of the programs are compatible to Python3 except some syntaxes.
If you are using Ubuntu, Redhat or any other Linux systems python is already installed by default. Otherwise just install using apt-get install python2, python-pip for Ubuntu and yum install python2, python-pip for centos based.
In windows you need to download installer msi file and then you can install python. If you install python in windows using installer you will get an interactive IDLE also which will be very helpful while you learning python. Below is the screen of IDLE in windows.
You can execute python syntax/lines in this IDLE.
Now open your cmd or terminal and type python , then you will get into python shell which is same as shown above, but only difference is IDLE gives more functionalities while we learn python we can use those. But no problem if you are running python in UNIX systems , at the end we are all going to write python code.
Python shell shown below.

0 Likes 158 Views
Difference between reduce and accumulate

This article helps to give an introduction of reduce fuunction and accumulate function.Both the functions are used to process the input_list as a sequential pairs.
I am going to explain the differences with the help of an example.
import functools
list = [1, 2, 3, 4, 5]
retVal = functools.reduce(lambda x, y: x+y, list)
Result: 15

0 Likes 111 Views
map, filter & reduce in python

map, filter and reduce are the functions by which we can achieve functional programming in python.
map: This applied the function definition to each item in the input_list.
map(function_to_be_applied, input_list)
Example : Squares of the elements in the input_list
items = [1, 2, 3, 4, 5]
squared = []
for i in items:

0 Likes 111 Views
Lambda functions in python

This article helps to give you a brief introduction of lambda functions, how to write a lambda function and gives you the code for traditional way of writing functions and lambda functions.
Name Origin: In any programming language a function is called as anonymous function if the specific function definition that is not bound to an identifier. Unlike normal functions which is defined by the key word def, the anonymous functions are declared with the help of lambda keyword.
lambda arguments: expression
we will look at examples with and without using lambda functions.
def square(num):
return num*num
square = lambda num: num*num

0 Likes 124 Views