Local and global variables in Python

Variables defined within a function are local to that function and cannot be accessed outside the function. Local variables are very loyal to their parent function and live and die with them. Now suppose I define a variable num1=0Β  outside functions, it is global. A global variable can be accessed within a function but cannot be modified, unless we declare the variable to be ‘global’ by explicitly mentioning so within the function. eg:

global num1
num1 = 5

Variables local to a function cannot be accessed outside a function and will throw an error if we try to do so. Global variables are an easy way to manage handlers without a lot of programming overhead.
Anytime we want to assign a global variable within a function, we must declare it as global in the function. If we try to reference a global variable within a function, without declaring it as global (a mistake obviously), we get an error. However, if we just assign a global variable without declaring it as global (again a mistake ofcourse), Py assumes it is just a local variable and doesn’t throw an error, but the result will be wrong.

Python 1

I am trying to learn Python and I think sharing what I learn on my blog will not only serve as a quick reference for me in future but will also help those who are always on the lookout to find and learn fun things. So here goes my first post, a summary of a few very simple things I have learnt.

Event driven programming: This means your program will not run forever, rather it will run for sometime and then wait for an ‘event’ to occur like a mouse click or a text input or a button press and so on. The program flow then passes to a ‘handler’ specific to that event who knows what to do in case its event is fired.
Lets look at an example, this is from a module called simplegui. Yes Python functions are housed in these nifty little packages called ‘modules’. I think that’s really very cool.

So I import simplegui module saying

import simplegui

Then I have 3 timer functions in this module namely:

mytimer = simplegui.timer_create(delay in ms,myhandler) which will create and return a timer object

mytimer.start() which will start the timer

mytimer.stop() which will stop the timer.

So if I define a function like

def myhandler():
print "Hello Sir"

and I create and start a timer object, I will have “Hello Sir” printed at regular intervals ! BTW printing something like “Hello Sir” is just a trivial example, I can make anything to trigger at regular timings with the power of timers in my hands. Mwahaha !

A few notes: When a handler runs, no other the event handler can be run, so if another event occurs while a handler is running, the event just gets into the event queue and waits to be pulled out of the queue after the current handler finishes executing. So the queue does the trick.

Cafe Leopold

I had some work to do with friends in CST on a Saturday morning. And what better excuse than this to check out the unexplored spots of the city. Imromptu plans were made and soon we were on our way to this quaint but very popular hotel.

Cafe Leopold:

This place is one of the oldest and most well known cafes in Mumbai. Leopold too was set up by an entrepreneurial and (I am guessing) foodie Irani gentlemen in 1871. This restaurant was one of the unfortunate targets of the dastardly terrorists who attacked Mumbai in 2008. Wounds of that fateful evening still remain on the cafe walls. But that perhaps is a symbolism for the spirit of Mumbai. No matter how badly she has been hit in the past, she just refuses to give up.

“It doesn’t matter how hard you get hit, but it is about how hard you can get hit and still keep moving forward”

Seen here is one of the bullet holes

This interesting contraption is something they call a ‘beer tower’ This 5 feet tall cylinder is filled with.. wait for it.. yes, BEER !! πŸ˜€ Fill your pints according to your pace. We curiously stared at the tables hosting this mammoth, quite a few of them got drained before we expected. Leopoldians surely love their beer.

 

 

 

 

 

 

Psst.. I am a teetotaller, so I had to settle for this little Mocha Frappe, which was absolutely yummy.

 

 

My friends ordered a Club Sandwich which had huge portions of chicken sausage. They claim it was the best club sandwich ever. The restaurant has a very lively feel to it and is a great hit among foreigners, the menu too is very international but caters to Indian tastes also. We finished with the ‘Leopold Special Cheesecake’ for dessert which was definitely the kind of dish you would want to go to Leo again and again for.

Leopold is one of those restaurants in Mumbai that have retained a distinctive character and aura. Everything that you see here right from the glasses, plates, beer mugs have a history of their own and speak volumes about Mumbai and her cosmopolitan and welcoming character. Definitely a must visit place.

Foodie haunts at Matunga – I (Classic)

Name : Classic

Place : very close to Don Bosco School, Matunga

This place is very close to my college and I was rather surprised that I hadn’t eaten here even once, my friends were much more surprised than I was and decided to drag me to Classic then and there without any further delay.

Classic greeted me with a heavy aroma of spices and strong flavors generally used in dishes that Indians like to call ‘Chinese’. It is definitely one of the better fastfood joints in Matunga and I was told by my friends that their Pav Bhaji was to die for. I went through the menu (which offered plenty of choices), nevertheless I decided to take my friends’ suggestion. I wasn’t disappointed at all as the Pav Bhaji indeed turned out to be quite something. Mumbaikars I feel absolutely love their Pav Bhaji and being the thorough Mumbaikar that I am have eaten this quintessential Bambaiyya dish at many places. Restaurants that manage to pull off this delightful dish with finesse automatically win my respect. Classic got very very close to that, if not bang on. The Bhaji was very tasty and well prepared. It came with a dollop of butter, (like Bhaji always has, and always should πŸ˜‰ ). The Pavs too were generously buttered and fresh. My friend ordered the Jain version of the dish (Jains don’t eat onions, an extremely important ingredient of Pav Bhaji or any tasty Vegetable dish for that matter). I tried some of his Bhaji and believe me, it was equally delicious as the normal one, if not more. #FoodieDelight knew no bounds.

On the bad side, the restaurant was a little congested, the waiters could have been a little more affable and the service surely wasn’t the best I had seen.

So here goes the report card:

Taste : 8

Ambience : 7

Service : 6

Value for money : 8

The Chinese joint I never tire of

Name : A1 Chinese

Location : Dombivli(E)

This is one restaurant, that me and my equally foodie friends keep visiting for their tasty Chinese fare at unbelievably cheap prices. They serve both veg and non veg dishes, but we always end up ordering the non-veg dishes. You can begin with one of their soups or starters, Chicken Manchow soup and Manchurian, being the best ones, easily beats a bad cold ! Proceed to their main course dishes, where you can choose from their assortment of noodles and rice dishes. Schezwan, Hakka, Manchurian, you are spoilt for choice. The meat is fresh, tender and succulent. The rice and noodles are nicely done. The food is loaded generously with heavy spices and sauces and hot gravy, but unfortunately, that’s the case with almost all the small Indian Chinese joints. If you aren’t a fan of the typical Chinese flavors that such places serve (Soya, Schezwan, lots of garlic, to name a few), you won’t like the food a lot. The portions are adequate and the prices are much lower than usual. You have an option of asking them to pack your food, enjoy it at home.

On the downside, I would say, the ambience is very poor. The place is cramped and can seat at the most fifteen to twenty people. Had it been any smaller, it wouldn’t have qualified as a restaurant. It isn’t well lit and badly needs a revamp. The waiters are quite uninformed.

So here goes the report card(on the lines of Rocky and Mayur’s )

Taste : 8

Ambience : 6

Service : 7

Value for money : 9
..And I have written my first restaurant review. Wohhoo !

Here’s to Mr. Nikhil, the courier guy who delivers my Flipkart shipments

Shopping online is one of my favorite things, Flipkart being my trader of choice coz of their promptness and awesome packaging, not to forget the free home delivery for orders exceeding Rs 300. Flipkart shipments to my house are usually brought by one Mr. Nikhil Patil. Unlike other courier guys, the packages he delivers always come with three lines of neat, clear writing in blue ink on the body of the packaging:

Nikhil Patil

9892767651

Fridge, Washing Machine, AC

Whenever he hands over the package, he politely points to what I believe, he must have so meticulously written on each and every package given to him for delivery and says, “Sir, if you ever need some help with your fridge, washing machine etc, just call me, I ll come immediately. Don’t forget to mention me to your friends.”

His words always put me in a contemplative mood. The gentleman knows how to repair complex machines that I am sure many of those who are much more qualified than him wouldn’t know, yet he works as a courier, delivering shipments from door to door. Many in our nation, especially among the youth, work as unskilled workers despite being capable of doing better in their lives. Tapping the potential of the youth in a largely ‘young’ nation like India is critical to growth and development.

If you live in and around Dombivli, and need help with the above mentioned appliances, please call Nikhil !! πŸ™‚

Link

while(Coursera) { Learning = Fun !!; }

Coursera is a place where magic happens ! It is an OpenCourseware platform where tens of thousands of students from thousands of places take hundreds of courses from the best schools of the world. The availability of Open Courseware has indeed ushered in an era of democratization of education, with quite a few universities offering online courses parallel to the real courses(taking place on the university campus) and having almost the same course content. Such virtual campuses are available to just anyone who has a computer and a stable internet connection. This is indeed ‘knowledge without boundaries of space and time’, not to forget the courses are absolutely free of charge. You don’t need hundreds of dollars anymore, just the will to learn, ( and ofcourse the internet connection we talked about too πŸ˜‰ )

As an Electronics Engg student, who is also interested in CS a lot, online courseware is particularly useful for students like me. In college we don’t have much of a choice in choosing courses that we like besides the electives. On the contrary, at Coursera(and other such platforms) there is absolute freedom about joining a class. There is this lovely green colored ‘Go to Class’ button that allows you to drop into a class whenever, wherever (even from in between of a course), once you have signed up for a course. Listen to lectures, answer the interactive quizzes, solve assignments and if you are sincere enough, you get a letter of accomplishment from the course instructors. Coming to the course instructors, they are the most chilled out professors I have encountered. Each one of them is one of the very best in his or her field and each one meticulously and painstakingly designs the contents of courses. But wait, that’s not all, there are also live forums and meetups, where nerds, backbenchers, star performers alike shoot questions at the profs and amongst themselves.

A special mention for the variety of courses at Coursera. There are courses ranging right from Game Theory, through Algebra, through Neuroethics, through Cosmology(Galaxies and cosmology), to something as different as Poetry Writing, and Music. The Course Catalog is an absolute pleasure to go through.

#Coursera #fun

Buongiorno !

And so here I am, back to blogging.. After a long hiatus I am back with a new blog. My old blog, I feel was rather flashy and showy. As opposed to that, my present blog is quite minimalistic and simple. Simplicity is an amazing quality.

A quick introduction, I am Abhishek, currently pursuing my Final Year BTech in Electronics fromΒ  VJTI, Mumbai. I am extremely passionate about technology, music, food and travelling. I love to code and would love to be a highly respected ‘code-ninja’ some day. I listen to a lot of Hindustani Classical and rock music. I am a Cancerian by sunsign and like a true Cancerian, I love the sea, perhaps a little more than my fellow Mumbaikars. I don’t know to swim but I fantasise about being able to go surf-boarding on a high tide some day.

That’s all for now