[Tutor] Newbie: First program - looking for feedback :)
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Jan 6 18:23:44 EST 2004
On Tue, 6 Jan 2004, Christian Wyglendowski wrote:
> > I find i am getting comfortable with GNU/Linux now, and it has
> > recently encouraged me to try my hand at programming; for those times
> > when you wished you had a little tool to do something :). The
> > possibilty of helping the open source commnunity by contributing to
> > software development etc is also a plus, although a distant dream at
> > this point. ;)
>
> Good goals. I have had the most fun with some of the little "tools"
> that I have written for mine and others' benefit. I hope to contribute
> to the open source world someday as well.
Hi Christian,
Yup. *grin* Here's an example of a tool that I wrote for myself just
today. It's called 'flip':
###
"""flip: A small utility to reverse the columns from lines in standard
input.
Todo: add delimiter option using optparse.
"""
import fileinput
for line in fileinput.input():
words = line.split()
words.reverse()
print "\t".join(words)
###
So say that I'm at a Unix command line, and I want to calculate md5sums:
###
-bash-2.05b$ md5sum flip
c957c64326962b9d7fa477ac00340751 flip
###
With 'flip', I can now reverse the order of the columns so that the
filename comes first:
###
-bash-2.05b$ md5sum flip
c957c64326962b9d7fa477ac00340751 flip
-bash-2.05b$ md5sum flip | flip
flip c957c64326962b9d7fa477ac00340751
###
Python is a great tool for augmenting the command line.
Talk to you later!
More information about the Tutor
mailing list