[Tutor] Introduction

Alan Gauld alan.gauld at btinternet.com
Sat Aug 18 19:25:39 CEST 2012


On 18/08/12 17:36, Ray wrote:

> I'm not certain why I'm diving into Python. My only coding experience
> has been using Bash scripts on my Ubuntu system for the past half dozen
> years, and so far I'm not particularly convinced that Python has any
> advantage FOR ME over what I have been using.

Python may not give you any new capability for the kinds of things you 
describe but what you should find is that the code although maybe a 
smidge longer will be much easier to maintain. It will often run a 
little bit faster too (occasionally a lot faster) and use less computing 
resources.

As with anything there will be a learning curve where it will feel a lot 
easier to just "knock something together is bash" but in time the Python 
approach will become more natural. Of course there will still be plenty 
of room for OS one liners. I still use bash and awk for short one-off 
jobs. But for things you do frequently Python is usually a better long 
term bet. And of course you can overlay a nice GUI to make those tools 
easier to use...

> In my Bash scripts I make generous use of sed and grep, with the
> occasional use of awk

Remember that python can do all of those jobs natively, so resist the 
temptation to just use os.system() or the SubProcess module. Thee is a 
place for those, but its not to do what awk/sed etc can do - thats 
usually better kept within Python.

> else would want...and although, as I look at my Python code so far, it's
> definitely hard-coded for a Linux system :-p. So much for that reasoning....

We look forward to seeing some of it in the future when you ask 
questions. But bear in mind my comments about avoiding os.system() etc 
unless its the last resort.

HTH,
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list