Live Chat!

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: 16686 | 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: 19251 | 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: 21188 | 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: 28007 | 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: 19051 | No Comments »

python: handle string from pipelines and list of param

* * * * * 1 votos

November 13th, 2007 mysurface

While I was searching ways to implement pipeline input for my python apps, I read an article from linuxjournal.com that mention about how easy that python can works with pipeline.
Here is the code quote from that article.
#! /usr/local/bin/python
import sys
sys.stdout.write(sys.stdin.read())
Well, I understand that served as a simple example to show how easy python can works with [...]

Posted in Developer, python | Hits: 18745 | 3 Comments »

python: how to identify the type of your variable

          0 votos

November 10th, 2007 mysurface

In python, every single variable is an object, every object must have a type, it is either data structure or class instances. Python’s variable can be dynamically change easily during runtime, for example
>>> d={1:’one’,2:’two’}
>>> print d
{1: ‘one’, 2: ‘two’}
>>> d=['one','two']
>>> print d
['one', 'two']

First line d is declare as dict data type, and after 3rd line, [...]

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

Help yourself in python

          0 votos

October 31st, 2007 mysurface

If your computer science student, you study IT, click with technology, python is not a snake for you. It is a scripting-like programming language that are so famous today. You can type python into google, the first link is not about the reptile but the programming language. There are plenty of apps and scripts written [...]

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

Use gprof to check your codes for performance issues

          0 votos

August 29th, 2007 mysurface

By reading the article Speed your code with the GNU profiler from IBM DevelopWorks, I have gain the knowledge of using gprof to easy my work to identify my module’s performance’s bottleneck. Here, I would like to share my experience on how I discover the clog of my codes.
Let us first look at [...]

Posted in Developer, gcc, gprof | Hits: 18441 | 5 Comments »

perform grep and make in vim

          0 votos

June 15th, 2007 mysurface

We can do grep and make in vim, the advantage of doing that in vim compare to terminal is you can use the result to track the error and warning for make or goto the line and files of the grep results.
How to make in vim?
:make
In order to make, the current directory must contain a [...]

Posted in Text Manipulation, grep, make, vi, vim | Hits: 21561 | 1 Comment »