Reading Files Line by Line in Python

You write a script in python which has to read a file, loop through each line to do some work. Seems easy right?

f = open('loulou.txt', 'r')
lines = f.readlines()
for line in lines:
	print line

Problem is when your file becomes big, let’s say 1500MB, the code will still run on your development laptop but it will fail on a server on cloud with 1GB of RAM. You’ll have an Out Of Memory error which can lead to some very important process being killed if OOM priorities are not mastered.

You can use the Collectiva service by NAYARWEB.COM to get alerted near-realtime whenever Out of Memory occurs on one of your servers.

To fix the code above, you can read the file line by line from the disk:

f = open('loulou.txt', 'r')
for line in f:
        print line

Is this always better? No. The current version will run slightly slower than the first code depending on your storage backend.

It’s amazing how little differences like these can have a huge impact on production servers.

Happy Monitoring to all System Admins out there 🙂

Car Not Start on Rainy Days

If I drove VW Polo everyday, it would start perfect and run perfect for months. But if I let the car sit for more than 24 hours, on the next day it would have lots of trouble to start the engine.

I’d have to wait for the sun to warm it a little and then It would turn on as if nothing was ever wrong with it.

The Cause:

It turns out that the rotor in the distributor had a huge hole in it.

So my dad cut a tiny piece of wire and put it inside the hole linking the 2 extremities of the hole. I think the inner stuff is graphite. He put it back in the car. And lo! It started despite the heavy rain! 😀

The Solution

But we decided to buy a new rotor in a car shop nearby for Rs 300. My car’s been great since. Noticed some performance improvement.

Take car of your car. Drive safe.

Abolition of Re-registration Duty for Cars in Mauritius

This morning on Facebook, I came across someone who posted the following:

Let’s have a look on NTA’s instructions on how to sell your car.

source: nta.govmu.org [accessed: 02/05/2017]
The procedures seems fair and easy and not costly. However, the “The deed of sale should be registered at the Registrar General’s Department” part will be very expensive. Why doesn’t the NTA put the all the cost in one place? Anyways, there are no direct links from that page to know how much you have to pay to register the deed of sale.

I had to google it.

The second link is the PDF which has the informations.

2 months ago, I wanted to buy a newer car. But with these exorbitant duties, I refrained.

https://www.facebook.com/NayarJoolfoo/posts/10210709586528792

Now we ask ourselves, how many old cars are involved in fatal accidents? Every time I watch the news, I see BMW, Mercedes, etc being crushed. Where are the old cars? Why are they so hated?

 

Older cars are used exclusively by poor people. Each time a poor person buys an old car, he has to pay Rs 6,500, Rs 10,400, Rs 13,000 for >1001cc, >1251cc, 1501cc respectively.

Math question for CPE students and adults too. [300 points]

Let’s assume each time an old car is sold among the poor, Rs 10,000 goes to the government. How many poor people it takes to pay for the new Pravind Jugnauth car which is valued at Rs 23,541,673? Please leave the answer in the comments.

Why are Mauritians so concerned about Nandanee Soornack?

Mauritians are bored. They love drama. I guess that’s why the media gives them dramas to keep their minds busy after pretending to be busy in 9-6 jobs.

Mauritian Media quoting Nandanee Sournack

Current politicians are abusing power. They are buying BMWs worth more than Rs 20 million rupees each. And our attentions are diverted to some ex-government agents who allegedly abused power. I don’t care anymore! Let’s stop the current ones from blowing our money and selling our beautiful country.

When the opposing party will take power in the next election, we’d reading articles about how the current government didn’t do its job and was corrupt. WTH?

When are we going to focus on TODAY, the day which needs fixing?

Why I read magazines backwards

I ain’t no bookworm. I got very short attention span like most facebookers and tweeps.

Magazines usually start with editorials and their front featured articles. That’s too much to digest at once.

One paragraph articles or short comics at the end are very easy fast and easy to read. As I move towards the front page, the articles get a little bit longer and deeper. My mind is in a more curious and grasping mode for that effect.

And some people thought I’m a fanatic! xP