[Tutor] is it a right choice?

Jeff Shannon jeff@ccvcorp.com
Thu Jul 3 13:37:04 2003


Payal Rathod wrote:

>Hi,
>Before I venture in the python infested world, I want to ask whether I
>am making a right choice by taking python as my first programming
>language. I cannot program in C, C++ or Java etc. I can *just* do little
>shell scripting.
>

Opinions vary, of course, and since you're asking in a Python form it 
should hardly be surprising that replies you get will be favorable 
towards Python ;)  

Still, Python was designed from the start to be a language that would be 
easy for *everyone* to learn, even nonprogrammers, and there's a growing 
trend of using Python as a first language for teaching programming.  So 
it seems reasonable to assume that it's a good choice for you.  :)

>My objective in learning a better language is that I have huge log files
>in my office and get many logs files from friends who are sytem admins.
>I love to analyse those files and find out browing habits of my compnay
>(from squid logs), most number of mails sent to a domain ( like
>hotmail), number of bytes data transferred thru' http, pop3 and smtp
>etc. I prefer to write my own programs to do these things.
>With rudimentary shell scripting knowledge analysing log files which are
>many times over 200Mb is difficult so I was seeking a language which can
>do these tasks beautifully without getting too much involved in
>underlying concepts.
>Am I looking for Python? Is Perl easier to learn for a newbie than
>python? Is it OK to continue with Python?
>

For this sort of thing, I think Python is perfect.  The interactive 
interpreter lets you play with your data, without needing a 
write/compile/run cycle, and there's lots of standard library modules 
that help you to handle standard protocols like http and pop3.  (I've 
used the Python interpreter and poplib to check my home email from work 
without bothering to set up a profile in my email client.)  Python has 
powerful string-handling capabilities, too, though there's a few minor 
tricks that should be kept in mind to keep large-scale string- and 
file-handling efficient.  Perl, in contrast, may arguably be a bit 
stronger on the string-handling, but its syntax is very complex and 
confusing.  It's much harder to figure out what's going on in a Perl 
program than it is to figure out a Python program -- this readability of 
Python is a *very* big advantage when it comes to learning, since it 
makes it much easier to pick up techniques from other programmers, not 
to mention a lot easier to see how that program you wrote last month 
works.  (Trust me, after a month or two have passed since you wrote a 
program, you'll need to figure out how it works all over again, almost 
as much as if someone else had written it to begine with...)

>Also can Python produce binary programs like perl (perlcc)?
>  
>

No, Python doesn't compile to binary, but that's not necessarily much of 
a disadvantage.  Since Python is interpreted in a (relatively) 
platform-neutral way, it's easy to write scripts that run equally well 
on Windows and Unix, without needing to compile a version for each 
platform.  And Python's dynamic nature (which is a large part of what 
makes it very difficult to compile to binary) has at least as many 
benefits as compiling to binary does -- the main advantage of binary 
code is speed, but that is not often an issue.  (And when it is, you can 
always write a Python extension in C, which does the speed-critical 
parts of your calculations in a compiled library while letting you 
handle the overall architecture in Python.)  

If the motivation for binaries is to have a single self-contained 
executable to distribute, there's several utilities (Py2exe, McMillan 
Installer) that will package up a set of Python scripts with an 
interpreter into a single executable archive.  This is not as 
space-efficient as a true compiled file, since it requires a new copy of 
the Python interpreter with each program, but it will allow your 
programs to run on computers that don't already have Python installed.

Jeff Shannon
Technician/Programmer
Credit International