October 21, 2009

Google Maps -- Double Standards

I am not very political but at least I know one thing, double standard sucks big time.

Arunachal is shown as a disputed territory for the rest of the world.

View Larger Map

And for the Chinese it is being shown as a part of China.


I am very disappointed and all I can say is that it shows Google turning into a very filthy organization.

Note --

Moral of the story is Google succumbs to pressure for a silly reason. It is a map to show where a place is on this globe, (location on earth with one of the names with which the place is called) and not a Political Map (no boundaries and one world). I guess one can show these places without political boundaries which will be consistent throughout the world? So will the usefulness of Google Maps or any such software diminish if it does not show political boundaries

October 14, 2009

Python tips and tricks: Flushing stdout

Many a times I need to redirect the output of a program to a file. For example

#> python test.py > outfile

However, the problem with this is that stdout is not flushed on each print command and some of the statements can still be in the buffer which can be painful at times based on the level of anxiety :).

We shall now see one of the quickest way to ensure that stdout is flushed. I have not seen a case where it didn't work (at least in Linux) and do not know how one can verify if this works at all times.

For example if your file is as follows:
  • def test():
    • j = True
    • while j:
      • time.sleep(1)
      • print("Hello:"+str(j))
    • print "Bye"
  • if __name__ == "__main__":
    • func()

Just add the following line to your code
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

This can be done as follows:
  • if __name__ == "__main__":
    • import os, sys
    • sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
    • func()