Search

19 September, 2018

Working with context processors and WITH statement

We use. We forget. This is for myself so I remember the magic called Context Manager. You already must have used the "with statement" for file handling, threads, socket and other operations. I am going to talk about creating you OWN context managers.

The magic operator to be used is : @contextmanager. It can be imported from the module "contextlib"

To create a context manager, use the decorator contextlib.contextmanager


@contextlib.contextmanager
def getListCounts(x):
    try:
        from collections import Counter
        yield Counter(x)
    finally:
        print 'No of elements in the list : %d' % len(x)

11 September, 2018

Regular Expressions. Lets not be greedy.

Recently faced a situation when I wanted to extracted parts of a html code. But then I realized, I have no control over the amount of information regex is giving me back.

Python: Running executables using subprocess module

There are many ways to run a bat/exe file but the most widely used is the subprocess module.
And I would like to clearly show, how exactly to do that. When should you use what arguments.
I am going to specifically talk about the check_output module .

A better example of Class Inheritance 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.

29 August, 2018

Python: Saving regular expression results in variables directly

Python Regular expressions has a powerful tools under it's regular expressions module which lets you create variables and save your search results directly.

It is called named groups . When you search for something and you want to save it in a variable when found, this is what you should use.

Setting your first Jenkins project.

Setup Jenkins on your local PC in minutes


Since you are here, I am assuming that you are trying to find out ,  how to start with Jenkins and you have no clue about it . If it's true, then you are in the best place possible .

This is a blog on Jenkins setup for those guys who have absolutely no idea what to do or where to start.

24 August, 2018

Regular Expressions: Look ahead and Look behind

Regular expressions are fun. There are two important concepts that are quite often sought for. Find something based on content that follows our search pattern . OR. Find something based on content that lies ahead. Let's see some examples to see what I mean.

LOOK AHEAD

LOOK AHEAD means , I want to see what lies ahead first, and then decide, to do something now.


Syntax of regex pattern:  pattern1(?=pattern2)