Live Chat!

Python vs Lua, data structure

          0 votos

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: 17299 | No Comments »

Python: Threading Callback Timer

          0 votos

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: 19921 | 1 Comment »

Experiencing with iPython

          0 votos

March 5th, 2008 mysurface

What is iPython? Is it something to do with Apple Macintosh? as stylish products like ipod and iphone? If you are enjoy coding python like me, yes ipython is a stylish and very interactive python interpreter.
Auto Complete
ipython support auto complete, which is the very first reason I use it. With auto complete features, it increase [...]

Posted in Developer, ipython, python | Hits: 14622 | 1 Comment »

Python: How to run a command line within python?

          0 votos

March 4th, 2008 mysurface

I always got this question in my mind. How to run a command line within python, get the output and manipulates it. Before I learn python, I was doing bash scripts all the while to helps me manipulates text which I get it from log files, or pipes out from some certain command line.
To [...]

Posted in Developer, python | Hits: 15707 | 5 Comments »

python: convey the exception traceback into log file

* * * * * 2 votos

February 27th, 2008 mysurface

Python is the interpreter language, you do not need to compile your code, and also you have no ways to check for your syntax error until you run your python script. Either syntax error or runtime error will be throw to standard output through python exception handler by default.
Python throw the exception with traceback info [...]

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

Python: Manipulate Date and Time variables

          0 votos

February 17th, 2008 mysurface

When comes to data time related calculations, we usually calculate for time difference, for example How long is the down time for a particular service? How many days or hours are used to finish a task? etc.
With python datetime and time class, it makes calculation simple.
Let us look at some simple examples of datetime [...]

Posted in Developer, python | Hits: 16824 | No Comments »

python: user define sorting with callback

* * * * * 1 votos

January 8th, 2008 mysurface

Theres a lots of people treated python as scripting language like bash, but I am going to tell you, python is real programming language. Python support callback like c/c++, and this feature is really God-like, because it is so simple to implement callback in python.
What is Callback?
In computer programming, a callback is executable code that [...]

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

Python: Careful with equal sign

          0 votos

December 8th, 2007 mysurface

To store data, object reference to a variable is very easy in python. For example, to assign an integer 5 to a
a=5
Same thing goes to string
str=”hello world”
Assign data to a data structured variable, let say list,
L=[1,2,3,4,5]
Even assign a function to a variable.
import sys
wstderr=sys.stderr.write
wstderr(”hello world\n”)

Observed that all of them uses equal sign, but CAREFUL! Sometimes, they [...]

Posted in python | Hits: 21308 | 4 Comments »

How to redirect output to a file as well as display it out

* * * * * 1 votos

December 6th, 2007 mysurface

To redirect standard output to a file is easy, you just need to use the redirection symbol, for example:
echo “hello world” > test.txt
But what if I want to display it out as well as store into a file?
Answer: tee
echo “hello world” | tee test.txt
Okay it seems very easy, how about append?
Related PostsRedirect stderr to stdoutVery [...]

Posted in Text Manipulation, pipeline, python, tee | Hits: 28419 | 1 Comment »

Python: How to access ssh with pexpect?

* * * *   1 votos

November 25th, 2007 mysurface

I have research on how to access ssh using scripting language for quite sometimes. For python, there are three libs is in my list:
Twisted - an event-driven networking engine written in Python.
Paramiko - implements the SSH2 protocol for secure connections to remote machines.
Pexpect - spawn a child application and control it as if a [...]

Posted in python | Hits: 19219 | No Comments »