Posts

Showing posts from February, 2017

One day trip to Malshej Ghat

Image
Maharashtra offers a host of choices when it comes to hills ,valleys and forts.  Activities like trekking or rappelling are most popular here. 

Malshej is one of those places that will offer you its own specialty. 

Rocky mountains, deep gorges, Beautiful tunnels , roads snaking around. Uncountable waterfalls.Dense forest and its habitat. 

It's a power package for a day. One day escape from the daily hassles of life. Western Ghats for you ladies and gentlemen.



How to reach:
A road trip will be the best option. You don't want to miss the chance of stopping anywhere you want and click pictures or just stare in awe. 



How to plan:Start at early morning 6 AM.Reach Malshej in 3 hrs.Straight away park at the MTDC.Have break fast at the restaurant inside.Stroll behind the hotel . There is a beautiful pathway made for tourists.





Find a good waterfall. Enjoy bathing in it. It's just awesome .


 Return home before night.
Best time to go:Rainy season. June - August
Precaution:Before you plan, ch…

Writing context managers using Python

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.contextmanagerdefgetListCounts(x): try: fromcollectionsimport Counter yield Counter(x) finally: print'No of elements in the list : %d' % len(x)

Let's now use the above context manager 

Example 1:
>>> with getListCount([10, 10, 12]) as c: print "Element occurring the most is %d" % c.most_common()[0][0] Element occurring the most is 10 No of elements in the list : 3
Example 2:
>>> with getListCount([10, 10, 12]) as c: print "Element occurring the least is %d"…

Python: Super class examples

Hi all. We are going to see some examples of usage of keyword 'super' here . 
Below code shows two classes Employee and Developer. A parent and a child.


classEmployee(object):def__init__(self,first,last):self.first=firstself.last=lastprint'Employee: {0}, {1}'.format(first,last)defhike_category(self):hike=0ifself.grade=='A':hike=(0.1*self.pay)+self.pay#percentelifself.grade=='B':hike=(0.15*self.pay)+self.pay#percentelifself.grade=='C':hike=(0.20*self.pay)+self.pay#percentreturn'{0},{1} gets {2}'.format(self.first,self.last,hike)classDeveloper(Employee):def__init__(self,fname,lname,grade,pay):super(Developer,self).__init__(fname,lname)self.grade=gradeself.pay=pay
Lets run the above program.

Results:

>>> d = Developer('arc', 'roy', 'C', 10000) Employee: arc, roy >>> d.hike_category() 'arc,roy gets 12000.0'
Observations and things to note
Above programming is done in Python 2.7. In 2.7, the class …