Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Python - fresh examples from recent courses

During courses, I write a lot of examples in front of delegates so that the get to see both a program to perform a certain task and how that solution was reached - after all, they'll be expected to modify and write programs after the course, and just showing them the final result would only be telling them a half of the story.

At the end of the course, these new programs are often useful for the delegates who attended, but not necessarily publishable to the wider world. They may lack comments, they may contain personal data, and they may have had 'side' demonstrations added into them which would make no sense to anyone who wasn't there. So I tidy up the examples, and add more comments too, before I public the useful ones. "Doesn't that take a long time?" someone asked me the other week. Yes - it does, but these new examples provide fresh alternative insights into how things are done, and build into a useful library.

I've been pretty full of cold / flu (?) for the last two weeks ... only firing on two cylinders rather than four ... so I've combined the extra examples from the Python course in Bristol (the week before last) and the public Python course from this week just concluded into a single post. All of the examples have additional descriptive comments - click on the [source] links to havea look.

Y102 - fundamentals

Printing out several values in the same print statement. You can provide a comma separated list of variables / expressions to a print statement, and Python will print them out one after another, with a space between them. If you want to suppress the space, you'll need to join the expressions together and the easiest way is often to connect them as strings using the "+" operator. [source]

Y103 - conditionals and loops

Conditionals in Python - conditions may be written without brackets, and the block of code that goes with the condition is inset rather than being surrounded by { to } or some other sort of delimiter. [source]

There's also an example (which I have placed in our "algorithms folder" - Q110 - which shows how we count the number of occurrences of a specific event within a loop. See [source]

Y105 - functions, modules and packages

A fresh demonstration of variable scope in Python - [source]

How xrange rather than range, and xreadlines rather than readlines, allow for efficient handling of large quantities of data without the need to store it all in memory - [source]

Calls to functions in another module (loaded from a separate file) - [source]

Y108 - string handling

Setting up Unicode text strings in Python - [source]

Raw and regular strings - [source]

Checking the type of data entered - [source]

Search and find, search and replace, and search and replace with the result of running code on what was found - [source]

Y109 - Exceptions

Exceptions to trap user errors - with a counter, so that if the user exceeds a certain number of erroneous inputs, the program exits - [source]

Reading from a remote URL ... with exception handling to trap the issue of the remote resource not being available [source]

Y110 - File Handling

Efficient programming to use huge amounts of data - example tests on 1Gbyte of text data records - [source]

Finding how much disc space is free from withing a Python program - using a wrapper to limit the OS dependent section to a set of functions isolated from the main code, which remains common. [source]

Sourcing data from a file using a "just in time" function so that no large intermediate list is produced [source]

Y111 - More on collections and sequences

Counting the number of times each visitor comes to a web site via a dictionary, then producing a sorted list. You're not able to sort a dictionary, but you can sort a list of the keys and then step through each of the keys in that sorted order. This example is also interesting in that it uses quite a complex sort function - it sorts firstly by the length of the IP address. If that doesn't tell records apart, it sorts by the number of visits from the IP address, and if there still isn't any distinction it sorts by the IP address itself. All of which is far longer to describe than to code - see [source].

Y112 - More OO Python

A "classic" demonstration - two slightly different types of people, with a lot of common (shared) code in a base class, and with differences defined in an extended class. A test program that uses that data, through Polymorphism to avoid the need for lots of conditional code, and also avoid the need for lots of repeated code - [source]. Sample data for that application is [here]

There's also a seasonal variation on the theme, with Christmas, Easter and Groundhog Day characters ... see [source]
(written 2010-12-11, updated 2010-12-13)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y110 - Python - File Handling
  [114] Relative or absolute milkman - (2004-11-10)
  [183] The elegance of Python - (2005-01-19)
  [1442] Reading a file multiple times - file pointers - (2007-11-23)
  [2011] Conversion of OSI grid references to Eastings and Northings - (2009-01-28)
  [2282] Checking robots.txt from Python - (2009-07-12)
  [2870] Old prices - what would the equivalent price have been in 1966? - (2010-07-14)
  [3442] A demonstration of how many Python facilities work together - (2011-09-16)
  [3465] How can I do an FTP transfer in Python? - (2011-10-05)
  [3558] Python or Lua - which should I use / learn? - (2011-12-21)
  [3764] Shell, Awk, Perl of Python? - (2012-06-14)
  [4438] Loving programming in Python - and ready to teach YOU how - (2015-02-22)
  [4451] Running an operating system command from your Python program - the new way with the subprocess module - (2015-03-06)
  [4593] Command line parameter handling in Python via the argparse module - (2015-12-08)
  [4663] Easy data to object mapping (csv and Python) - (2016-03-24)
  [4708] Scons - a build system in Python - building hello world - (2016-10-29)
  [4717] with in Python - examples of use, and of defining your own context - (2016-11-02)

Y103 - Python - Conditionals and Loops
  [299] What - no switch or case statement? - (2005-05-03)
  [353] Wimbledon Neck - (2005-06-20)
  [657] The ternary operator in Python - (2006-03-25)
  [668] Python - block insets help with documentation - (2006-04-04)
  [788] New - Conditional expressions in Python 2.5 - (2006-07-01)
  [835] Python - when to use the in operator - (2006-08-16)
  [909] Python is like a narrowboat - (2006-10-30)
  [1201] No switch in Python - (2007-05-23)
  [1477] Decisions - small ones, or big ones? - (2007-12-18)
  [1661] Equality, sameness and identity - Python - (2008-05-31)
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [2899] Groupsave tickets - 3 or 4 train tickets for the price of 2 - (2010-08-02)
  [3200] How a for loop works Java, Perl and other languages - (2011-03-12)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [3439] Python for loops - applying a temporary second name to the same object - (2011-09-14)
  [3620] Finding the total, average, minimum and maximum in a program - (2012-02-22)
  [3762] Learning to program - the if statement. Python. - (2012-06-12)
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
  [4092] Identity in Python - (2013-05-17)
  [4210] If elif elif elif - multiway selection in Python - (2013-11-16)
  [4322] Learning to Program - the conditional statement (if) - (2014-11-21)
  [4323] Learning to program - Loop statements such as while - (2014-11-22)
  [4402] Finding sum, minimum, maximum and average in Python (and Ruby) - (2015-01-19)
  [4541] Setting up and tearing down with the Python with keyword - (2015-10-16)
  [4545] Method, Class, Module, Package - how to they relate in Python? - (2015-10-17)
  [4713] Equality (in Python) - (2016-10-30)
  [4723] Conditional operators in Python - (2016-11-05)

Y102 - Python - Fundamentals
  [328] Making programs easy for any user to start - (2005-05-29)
  [633] Copying a reference, or cloning - (2006-03-05)
  [748] Getting rid of variables after you have finished with them - (2006-06-06)
  [956] Python security - trouble with input - (2006-11-30)
  [1430] Integer v float - Python - (2007-11-12)
  [1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
  [1461] Python - input v raw input - (2007-12-06)
  [1878] Pascals Triangle in Python and Java - (2008-11-10)
  [2368] Python - fresh examples of all the fundamentals - (2009-08-20)
  [2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
  [3181] Beware - a=a+b and a+=b are different - Python - (2011-02-23)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
  [3886] Formatting output - why we need to, and first Python example - (2012-10-09)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [4442] Mutable v Immuatble objects in Python, and the implication - (2015-02-24)
  [4712] A reminder of the key issues to consider in moving from Python 2 to Python 3 - (2016-10-30)


Back to
XML handling in Python - SAX, DOM and XSLT examples
Previous and next
or
Horse's mouth home
Forward to
Can you trust the big brand names?
Some other Articles
Making the most of critical emails - reading behind the scene
Sizers (geometry control) in a wxPython GUI - a first example
Object Oriented Programming for Structured Programmers - conversion training
Can you trust the big brand names?
Python - fresh examples from recent courses
XML handling in Python - SAX, DOM and XSLT examples
wxPython - simple example to add GUI to a server log file analysis
Santa Special - rather more special than usual - December 2010
TransWilts Rail News ... Melksham (Santa Special) Edition ... 5th December 2010
Royal Wedding. How William and Catherine have changed our schedule
4759 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, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 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., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3083_Pyt ... urses.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb