Live Chat!

Serialize INI configuration to python dictionary

0 votos Vota!!

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=192.168.1.4
Port=2143

#
# LOG section contains logging settings
#
[LOG]
LogLevel=5
LogPath=/var/log
LogType=Info Trace Error Debug

I [...]

Posted in Developer, python | Hits: 89032 | 1 Comment »

Does scons outperforms autoconf and makefiles?

3 votos Vota!!

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.
In [...]

Posted in python | Hits: 124432 | 1 Comment »

python: simple http server for file sharing

5 votos Vota!!

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 192.168.1.1, in firefox you can ask [...]

Posted in python | Hits: 134865 | 6 Comments »

Bit shifting can be done in python just like in c

1 votos Vota!!

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 “0×0001 << [...]

Posted in Developer, python | Hits: 144899 | 2 Comments »

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

3 votos Vota!!

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 lock it. [...]

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

Python: Manipulate string or binary bytes with StringIO

2 votos Vota!!

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()

str.write(”Hello, “)

str.write(”my name is “)

str.write(Name)
print str.getvalue()
The same way, you [...]

Posted in Developer, python | Hits: 145228 | 12 Comments »

python: writing binary file

2 votos Vota!!

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 files. [...]

Posted in python | Hits: 112570 | 4 Comments »

Python vs Lua, data structure

0 votos Vota!!

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 list, we need [...]

Posted in Developer, Lua, python | Hits: 50148 | 4 Comments »

Python: Generating graphs with matplotlib

2 votos Vota!!

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: 39703 | 3 Comments »

Python: Threading Callback Timer

1 votos Vota!!

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: 38536 | 4 Comments »