Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
Two days of demonstration scripts in Python

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
  [4236] Using Python to analyse last years forum logs. Good coding practise discussion. - (2014-01-01)
  [3935] Whether you have programmed before or not, we can teach you Python - (2012-11-25)
  [3911] How well do you know Perl and / or Python? - (2012-11-04)
  [3903] Python Programming class for delegates who have already self-taught the basics - (2012-10-25)
  [3902] Shell - Grep - Sed - Awk - Perl - Python - which to use when? - (2012-10-22)
  [3816] Want to escape the Olympics? Learn to program in the countryside! - (2012-07-23)
  [3798] When you should use Object Orientation even in a short program - Python example - (2012-07-06)
  [3519] Python - current versions and implementations (CPython, Jython, IronPython etc) - (2011-11-13)
  [3489] Python courses and Private courses - gently updating our product to keep it ahead of the game - (2011-10-20)
  [3463] Busy weekend of contrasts. - (2011-10-03)
  [3076] Python through the Snow - (2010-12-01)
  [2822] Python training courses for use with ESRI ArcMap software - (2010-06-23)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [2504] Learning to program in ... - (2009-11-15)
  [2367] Learning to program - how to jump the first hurdles - (2009-08-20)
  [2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
  [2227] Learning PHP, Ruby, Lua and Python - upcoming courses - (2009-06-11)
  [2020] Learning Python - many new example programs - (2009-01-31)
  [2017] Python - a truly dynamic language - (2009-01-30)
  [16] Python training - (2004-08-16)


Back to
A first demonstration of OO, including polymorphism
Previous and next
or
Horse's mouth home
Forward to
From Lymington by train - last of the slammers
Some other Articles
Websitemediasolution and a goldfish called Carl Johnson
Signwriting is dead. Long live the sign.
Easing off in our 50s?
From Lymington by train - last of the slammers
Two days of demonstration scripts in Python
A first demonstration of OO, including polymorphism
Lymington, New Forest - some pictures
Great Western Route Utilisation Strategy - Draft for Consultation
Dynamic / changing images on your web page
Writing with our customers words
4252 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2394_Two ... ython.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat