For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.
Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!
I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Python module Y110
Exercises, examples and other material relating to training module Y110. This topic is presented on public courses Learning to program in Python
, Python Programming
How to open a file in Python and how to read it line by line into a string, or all at once, into a list. Also how to overwrite a file or add to an existing file, and how to check existing files on your file system.
|Articles and tips on this subject
|with in Python - examples of use, and of defining your own context
The with keyword in Python lets you set up an object with a block scope and a defined closure. It's implemented in the standard file handle object library - see example at [here] and you can implement it for your own object using the __enter__ and __exit__ methods - example [here]. Note that the __exit__ ...
|Scons - a build system in Python - building hello world
It's a build system!!
Like Make (if you're familiar with that) or Ant (if you know that!)
The initial problem being solved ...
You have a whole lot of different development files (source files, libraries, manual text, configuration, etc) and a whole load of steps you use to convert those ...
|Easy data to object mapping (csv and Python)
Data files with each line being a record, and a number of 'columns' of information relating to each record on each line are a very common way of information being passed around - in essence a spreadsheet of data. And a sensible way for programs to handle that data is for each row / record to be converted ...
|Command line parameter handling in Python via the argparse module
A new example from the Python course just completed - looking at command line parameters through the argparse module from the standard Python library (2.7 and 3.2 onwards), and XML handling through the xml.etree.ElementTree module (2.5 onwards)
Here's code setting up an argument parser:
|Running an operating system command from your Python program - the new way with the subprocess module
Python's subprocess module has replaced a series of other modules, and if you're writing new code which calls operating system commands you should use this module in perferance to the older stuff. Easy examples at [here].
The "interesting bit" in various languages is not so much how you cal other ...
|Loving programming in Python - and ready to teach YOU how
I like programming in Java, but I love programming in Python. It's been a real pleasure to get back to Python this morning. I'm teaching a private course in Cambridge this week, and a public python course the following week. And a new example as work my hand back in ...
Scenario - I require to read ...
|Shell, Awk, Perl of Python?
Very frequently, IT system users find they've got a data file in one format and they need to filter it and transform it. On Linux and Unix systems, utilities such as grep and cut were the tradtions, perhaps with some awk.
Perl provided a single-program replacement for shell scripts that bolted together ...
|Python or Lua - which should I use / learn?
"Should I learn and use Python or Lua" - a question to me. The questioner was perceptive, knowing that he shouldn't try to learn lots of languages at the same time, and that he should always limit the "basket" of languages used within his applications - in fact, he was wondering if he could select just ...
|How can I do an FTP transfer in Python?
"If you think someone's probably done it before, they probably have .... and it's probably available to you" A good answer to many questions of the form "can I do xxxxx in Python?"
Question today "can I do an FTP transfer from Python"
Answer "Yes" [but I had a look around and discovered there was on ...
|A demonstration of how many Python facilities work together
Many of our demonstrations on the Well House Consultants site show individual features of a language - taken in isolaion to show you how they work. However, during a course we usually write further examples to show you how features work in combination to give a total result / solution to an application.
|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 ...
|Old prices - what would the equivalent price have been in 1966?
What did a cup of tea in a café cost 10 years ago? 20 years ago?
What was the rail fare from London to Manchester in 1966, 1976, 1986, 1996 and 2006?
Such questions prove to be very hard to research and find answers for on the Internet. I suspect that's partly because the Internet wasn't around ...
|Checking robots.txt from Python
The robots.txt file - which well behaved automata check to see whether they are welcome on a web site - has two directives in its base specification ' User-Agent and DisAllow. You will find some other directives used, and you will find some sites who have a robots.txt file that has blank lines after ...
|Conversion of OSI grid references to Eastings and Northings
In both Ireland and the UK, the Ordnance survey divides down the country into a series of lettered 100km x 100km squares, represented by 1 letter (Ireland) or 2 (UK mainland), and then measures / reports and Easting / Northing within that square.
ST645332 (UK, box ST, 64.5 km east, 33.2 km ...
|Reading a file multiple times - file pointers
When you open a file for read, you create a "file pointer" which knows where in the file you are, and each time you read from the file this advances so that you get the next piece of data each time you do a read. Usually you don't see the file pointer at all - it's internal - and you think nothing ...
|Relative or absolute milkman
Rather contrary to current trends, we've just started taking regular deliveries of milk (+ bread + eggs) at our training centre from the local milkman. As we grow busier, it's more effective to have someone deliver to us as part of his round rather than having to make a special trip out. And our "mint ...
Examples from our training material
| import CSV data into dict
| Read whole file, report on lines matching a pattern
| Reading a file line by line
| Object using generator - directory file traverser
| Parsing a large file, looking for matching lines
| polymorphism in action
| Jumping around an input file (random access)
| Improved version - program to handle data recently appended to a log file
| Short file parser
| File checks - is it a directory, when was it modified
| Fixed Length Record to CSV
| Read from a URL as is reading from a file
| Soccer grounds - Python
| Inflation Calculcator - what would it have cost?
| Inflation data - UK - annual factors
| using a generator to source data from a file
| json and csv handling
| Trapping a non-existant file error
| Handling huge data
| Find the title of a web site
| List a directory sorted by age of object
| Checking whether a file exists, and things about it ...
| running OS subprocesses in Python
| Disc space free within an application
| File overwrite and append in python
| Read file into list and process each line
| using with to limit the scope of a file handle
PicturesWriting a Python program
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
Opening and reading from files.
File system Checks.
Reading a web page.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.