Serialize INI configuration to python dictionary

August 30th, 2009 mysurface

A lots of configuration file is in the format of INI, if we manage to serialize INI configuration to python dictionary, we can write python scripts to analyse and generate back to INI files. Below is the sample of INI configuration: config.ini # # GENERAL section contains generic configuration # [GENERAL] IP= Port=2143 # # […]

Posted in Developer, python | Hits: 252271 | 20 Comments »

Does scons outperforms autoconf and makefiles?

May 28th, 2009 mysurface

SCons is a software construction tool (build tool, or make tool) implemented in Python, that uses Python scripts as “configuration files” for software builds. Based on the design that won the Software Carpentry build tool competition, SCons solves a number of problems associated with other build tools, especially including the classic and ubiquitous Make itself. […]

Posted in python | Hits: 196801 | 3 Comments »

python: simple http server for file sharing

May 15th, 2009 mysurface

You do not need to setup apache server just to hosting your file for sharing. If you have python 2.5 and above, you can do this at the targeted directory to share. python -m SimpleHTTPServer 9914 9914 is the port number I choose to host my web, assume my IP is, in firefox you […]

Posted in python | Hits: 241243 | 13 Comments »

Bit shifting can be done in python just like in c

April 1st, 2009 mysurface

It was amazing to discover that I can do bit shifting in python just like in c, the syntax makes no different at all. Let us look at how easy I can do a bit shifting. I write an example loop by shifting the bit leftwards. for i in range(0,10): print “0x0001 << %d = […]

Posted in Developer, python | Hits: 220744 | 4 Comments »

How can I avoid running a python script multiple times? Implement file locking.

March 13th, 2009 mysurface

Sometimes we just need a single instance of the python script to run at a time. Meaning, the python script itself should detects whether any instances of himself are still running and act accordingly. Well, how to do it? The idea is simple, the first instance of the python script will open a file, and […]

Posted in Developer, python | Hits: 243726 | 11 Comments »

Python: Manipulate string or binary bytes with StringIO

November 25th, 2008 mysurface

Sometimes it is not convenient to construct string using equal (=) like this: str = “Hello, ” … str = str + “my name is ” … str = str + Name print str In python, we have string stream (StringIO) that will behave like file stream, you can construct your string like this: str=StringIO() […]

Posted in Developer, python | Hits: 213827 | 7 Comments »

python: writing binary file

November 20th, 2008 mysurface

Python is the best scripting language which I found it out perform Bash script as well as Lua. I like python’s scripting syntax, which is make sense and very convenient in string manipulations. Its now come to binary format manipulation, how convenient is python? I have carry out some research on python into writing binary […]

Posted in python | Hits: 308240 | 61 Comments »

Python vs Lua, data structure

June 28th, 2008 mysurface

In python, we have various type of data structure, such as list, set, tuple, dictionary etc, but in Lua, we only have table. Table in Lua can be used as array, list, dictionary or object. Let see how you we construct list from Lua table. t = { ‘a’,’b’,’c’,’d’,’e’,’f’ } To print out the whole […]

Posted in Developer, Lua, python | Hits: 102237 | 8 Comments »

Python: Generating graphs with matplotlib

June 5th, 2008 mysurface

Matplotlib is a python 2D plotting library that can produce dots lines, histograms, power spectra, bar charts, pie charts, scatterplots, etc. With few lines of codes, you can generate quality graphs into various image format such as eps, jpeg, pdf, png, ps, svg. You may want to check out the screenshots includes with sample codes. […]

Posted in ipython, python | Hits: 85522 | 5 Comments »

Python: Threading Callback Timer

March 27th, 2008 mysurface

It is very common that we need to run certain routines periodically, thats why in *nix environment we have cron and in windows OS we have task scheduler. But there comes a time, we may need to execute certain routines finite times within our scripts. Under certain circumtances routines may need to run at background, […]

Posted in Developer, python | Hits: 90817 | 6 Comments »