I've spent the last two days introducing Python to a group of nine delegates (and, naturally, enjoying doing so). As I usually do, I have wrote a lot of new examples to show not only how the language and programs work, but also the
thought process behind writing them. At the delegate's request, I have added the examples onto our web site --- linkable by the delegates (and anyone else who cares to take a look) from the following list:
EARLY DEMONSTRATIONS
early python demonstration - using, re-using, copying variables
first real application - simple calculation
FUNCTIONS, FROMs and IMPORTS
A file of functions for 'from' or 'import'
file to be included to bring in application globals
loading application globals
How EVERYTHING is an object - even functions!
Hiding algorithms in functions - 'encapsulation'
Using a generator to avoid a large intermediate list - control
lists of functions, lambdas, callbacks (posh/flexible ways to use functions)
Generator function to prevent need for intermediate list
LISTS
ways of looping through a list
Some early list demonstrations!
Lists, lists of lists, mutable and immutable
generatings lists of 365 elements to convert day of year to month and day
Use of xrange rather than range to avoid huge intermediate lists
Trying to modify a tuple
FILES and OTHER DATA INPUT / OUTPUT
A one-liner to print a file's contents
File read and write - program 'samples' every 10th line of a log file
Reading a file line by line (good for huge files)
Reading a web page 'as if it was a local file'
Running an operating system command via a pipe
STRINGS and REGULAR EXPRESSIONS
Some examples of the % (string formatting) operator
Regular Expression to extract data from log file (and dictionary analyse)
OBJECTS
First steps in Object definition and use
Sample class with test harness too
Converting a file on disc to a list of objects in memory
I will add some notes, based on comments received about some of my examples recently. These are little demonstration programs. I would use standards such as a variable naming standard in 'live' programs - to avoid confusion about spelling and what variables do later. I would comment my programs far better. I would include documentation strings. I would validate user input ....
I talk about such things at great length on ALL courses because they are vital! but in some of these early examples, they would extend the course running time and pad out the source code so that it was hard to find the real nubbs!
OK ... If you want to learn Python / see me set up things like this and fully understand the examples, the course you need is
Learning to program in Python if you have never programmed before, or
Python Programming if you are converting from C, C++ or some other language
P.S. - come back here in a few hours / I'll go through and sort the programs into a more logical order, and add a few comments to the sources. But I know there is one delegate who is BUS-ting to get on ;-) I have been back ... sorted the examples into a more sensible order above, and added comments into most of them so that when you click on the link you'll find them better documented. Enjoy!
(written 2009-09-05)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y050 - Python - General [16] Python training - (2004-08-16)
[2017] Python - a truly dynamic language - (2009-01-30)
[2020] Learning Python - many new example programs - (2009-01-31)
[2227] Learning PHP, Ruby, Lua and Python - upcoming courses - (2009-06-11)
[2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
[2367] Learning to program - how to jump the first hurdles - (2009-08-20)
[2504] Learning to program in ... - (2009-11-15)
[2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
[2822] Python training courses for use with ESRI ArcMap software - (2010-06-23)
[3076] Python through the Snow - (2010-12-01)
[3463] Busy weekend of contrasts. - (2011-10-03)
[3489] Python courses and Private courses - gently updating our product to keep it ahead of the game - (2011-10-20)
[3519] Python - current versions and implementations (CPython, Jython, IronPython etc) - (2011-11-13)
[3798] When you should use Object Orientation even in a short program - Python example - (2012-07-06)
[3816] Want to escape the Olympics? Learn to program in the countryside! - (2012-07-23)
[3902] Shell - Grep - Sed - Awk - Perl - Python - which to use when? - (2012-10-22)
[3903] Python Programming class for delegates who have already self-taught the basics - (2012-10-25)
[3911] How well do you know Perl and / or Python? - (2012-11-04)
[3935] Whether you have programmed before or not, we can teach you Python - (2012-11-25)
[4236] Using Python to analyse last years forum logs. Good coding practise discussion. - (2014-01-01)
[4295] A longer Python ... training course - (2014-09-16)
[4408] Additional Python courses added to our schedule - (2015-01-29)
[4434] Public training courses - upcoming dates - (2015-02-21)
[4558] Well House Consultants - Python courses / what's special. - (2015-10-28)
[4656] Identifying the first and last records in a sequence - (2016-02-26)
[4712] A reminder of the key issues to consider in moving from Python 2 to Python 3 - (2016-10-30)
Some other Articles
Websitemediasolution and a goldfish called Carl JohnsonSignwriting is dead. Long live the sign.Easing off in our 50s?From Lymington by train - last of the slammersTwo days of demonstration scripts in PythonA first demonstration of OO, including polymorphismLymington, New Forest - some picturesGreat Western Route Utilisation Strategy - Draft for ConsultationDynamic / changing images on your web pageWriting with our customers words