Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
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))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Python module Y110
File Handling
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 subjectupdated
4717with 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__ ...
4708Scons - a build system in Python - building hello world
Scons ... 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 ...
4663Easy 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 ...
4593Command 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:   parser ...
4451Running 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 ...
4438Loving 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 ...
3764Shell, 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 ...
3558Python 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 ...
3465How 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 ...
3442A 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. On ...
3083Python - 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 ...
2870Old 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 ...
2282Checking 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 ...
2011Conversion 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. Example: ST645332 (UK, box ST, 64.5 km east, 33.2 km ...
1442Reading 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 ...
114Relative 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
analysethatbusstop   import CSV data into dict
coster.py   Read whole file, report on lines matching a pattern
costhuge.py   Reading a file line by line
dirStream.py   Object using generator - directory file traverser
dmoz.py   Parsing a large file, looking for matching lines
dsa   polymorphism in action
fff   Jumping around an input file (random access)
fgfg   Improved version - program to handle data recently appended to a log file
file_first   Short file parser
filechex   File checks - is it a directory, when was it modified
flr   Fixed Length Record to CSV
grabpage.py   Read from a URL as is reading from a file
grounds.py   Soccer grounds - Python
inflate   Inflation Calculcator - what would it have cost?
is.xyz   Inflation data - UK - annual factors
j2   using a generator to source data from a file
jdemo   json and csv handling
lost.py   Trapping a non-existant file error
majorcooker.py   Handling huge data
n2   Find the title of a web site
pinorder.py   List a directory sorted by age of object
pstat.py   Checking whether a file exists, and things about it ...
sp   running OS subprocesses in Python
sys.py   Disc space free within an application
tablog.py   File overwrite and append in python
wac1   Read file into list and process each line
widem   using with to limit the scope of a file handle
Writing a Python program
Background information
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.
Writing files.
File system Checks.
Reading a web page.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses 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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 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.info/resources/Y110.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb