Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

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 Y115
Additional Python Facilities
Exercises, examples and other material relating to training module Y115. This topic is presented on public courses Learning to program in Python, Python Programming, Intermediate Python

Python is a wide-ranging language, so you won't have learnt everything about it on the early stages of your course. In this module, we assume fundamentals knowledge, and we go on to cover some of the more advanced features of the language that you'll need as you go on to write larger applications of the type that Python's so well suited to.

Related technical and longer articles
Python threads - a first example
Pattern Matching - a primer on regular Expressions
Interfacing applications to a MySQL database engine

Articles and tips on this subjectupdated
4298Python - an interesting application
Python's in use in a very wide variety of applications ... one of the more noteworthy that we got involved in recently was in robot programming .... here's our Python Course delegate with his robot. Python is an ideal language for tailoring C / C++ applications such as real time control systems as ...
2014-09-18
 
4211Handling JSON in Python (and a csv, marshall and pickle comparison)
JSON - JavaScript Object Notation - has become the data encoding standard of choice for many applications far removed from the "Javascript" of its name. It's a compact, readable format which allows collections within a language (that would be lists and dicts in Python, for example) to be encoded into ...
2013-11-19
 
4085JSON from Python - first principles, easy example
Here's a short example of how to pick up a JSON feed from a URL in Python. All the examples I came across looked very complicated, so I thought I would write one that's really straightforward: Open a remote URL feed that provides a JSON object:   response = urllib2.urlopen('http://www.wellho.net/services/pix.json') Read ...
2013-05-18
 
3469Teaching dilemma - old tricks and techniques, or recent enhancements?
Where there's something that's a frequent requirement on one of the subjects we teach, but can be hard to achieve, we'll spend more than just a minute or two covering it on our courses. After all, the tips and techniques of how to make the most of a programming language are every bit as important as ...
2011-10-08
 
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 ...
2011-09-16
(longest)
463Splitting the difference
Perl's split function takes a string of text, and divides it up at a delimiter of your choice into a list of shorter strings ... it's one of the "power tool" functions of Perl and a vital part of the language. So how come that you can write a Tcl program and use its version of split - or omit the split ...
2011-03-01
 
3089Python regular expressions - repeating, splitting, lookahead and lookbehind
If you're looking for part of a string that's repeated again later in the string, you can capture the first occurrence and then use a back reference (\1, \2 etc) to refer to "same again". In Python, you can also name the element that you want to repeat - examples [here]. If you have a number of fields ...
2010-12-17
 
2790Joining a MySQL table from within a Python program
Python is a big subject. MySQL is a big subject. Yet the two fin so well together that they can be firmly linked, and work well together, using the tiniest drops of glue. I've provided examples here before, but in answer to a request from a recent delegate, I've just added a fresh example onto our ...
2010-06-02
 
2786Factory methods and SqLite in use in a Python teaching example
I've just uploaded a neat little example - [here] from last week's Python course - it's amazing what you can do in a very few lines of code. The application scenario is that we have a database of customers - some are residents at our hotel and others are delegates on our courses. Being mercenary folks, ...
2010-06-02
 
2721Regular Expressions in Python
I took advantage of the lack of a whiteboard yesterday to write notes on the screen - in an edit window - while I was teaching a class about regular expressions, and how they're used in Python. Which has resulted in a rather nice example that's now online [here]. Regular expressions can frighten newcomers. ...
2010-05-16
 
2765Running operating system commands from your Python program
As from Python 2.6, os.popen and friends are deprecated methods and you should use the subprocess module for subprocesses. So that's the way to go if you want to run operating system commands. New example showing this - [here] Starting with: from subprocess import * I can run a process and allow ...
2010-05-15
 
2764Python decorators - your own, staticmethod and classmethod
Python Decorators are wrappers that you may apply around methods. So they're rather like the bread around a sandwich. There are a number of standard decorators provided with Python - such as @classmethod and @staticmethod (see [here]) which allow you to turn methods into unbound (static, class) ones. ...
2010-05-14
 
2746Model - View - Controller demo, Sqlite - Python 3 - Qt4
The Model - View - Controller approach to application design keeps the Graphic User Interface (the view) separate from the database (the model), with the controller in between the two, describing how the data is displayed, and how changes to the data are saved away in the database. By separating the ...
2010-04-29
 
2745Connecting Python to sqlite and MySQL databases
For developing a Python application, and for light use, the SQLite database may be a good choice ... but then you may want to be able to expand the system to use a central database with a more classic server such as MySQL at a later date. Using Polymorphism in Python, and with a careful choice of which ...
2010-04-28
 
2655Python - what is going on around me?
If you want to find out what's going on around you in a Python program, you can uses your system's environment variables via the os.environ module - the keys() method telling you which environment variables are available to you. There's an example [here] from our Python Programming training course. Python ...
2010-03-03
 
2462Python - how it saves on compile time
Python is interpreted every time you run the code ... or that's the simple first story you're told. But really it's not that simple ... and not that inefficient. When you run a Python program, it is not interpreted line by line as you run it - it is interpreted all at once before it's run at all, ...
2009-10-20
 
2435Serialization - storing and reloading objects
In most of the languages we teach, data is held in memory on a "heap" with a "symbol table" holding the names of the variables, where they are stored, and what type of information the (currently) contain. When you write simple variables out to a file (or the screen) functions like print or puts (Tcl) ...
2009-10-04
 
2407Testing code in Python - doctest, unittest and others
The doctest and unittest modules of Python allow you to provide test harnesses for your classes / packages. Designing applications from the bottom up, you'll want to ensure that each of your code levels works and works well. You'll want to provide an example of what it should do for the next level ...
2009-09-17
 
1136Buffering output - why it is done and issues raised in Tcl, Perl, Python and PHP
When you go to board a plane at Heathrow, do the ground staff admit the passengers one at a time, ensuring that each is seated before the next boards, and sealing and re-opening the main doors between each? What a stupid and inefficient system that would be!! The same thing applies when you're programming ...
2009-08-31
 
901Python - listing out the contents of all variables
You can often guess which course I'm giving by the topic of the my daily writing .... "How do I list out the contents of all variables with names starting v-a-r ... a question from yesterday. The immediate answer: # print all variables starting with "var" sum = 9 var3 = 78 var6 = 99 varsity = 56 variable ...
2009-01-01
 
1876Python Regular Expressions
Python supports string pattern matching to regular expressions, using Perl style regular expressions. The re module - loaded via   import re brings the appropriate elements into your program ... ready to use. Patterns that you want to match against are called Regular Expressions and are created ...
2008-11-08
 
1149Turning objects into something you can store - Pickling (Python)
If you're working with objects in an OO language and you want to transfer them to another computer ... or simple save them from the current application for reloading into that application or another one on the same computer later on, you need to serialize the objects. Data within OO programming languages ...
2008-10-11
 
239What and why for the epoch
The Epoch occurred on 1st January 1970 ... at midnight, at the start of the day, GMT. It's an important concept in many programming languages, which work with times and dates before and after the epoch - it means that you can compare dates and times easily, even where month ends and different timezones ...
2008-05-16
 
1337A series of tyre damages
Warwick, 11 a.m., Saturday, for later posting. I left Maastricht yesterday evening at quarter past four, was at my overnight stop in Kent from 11 p.m. to 5:30 a.m., and should have reached Birmingham at around 08:00 ready for the Python Conference - Pycon. So want went wrong? Debris on the motorway! ...
2007-09-11
 
1336Ignore case in Regular Expression
Do you want to ignore case in a regular expression? There are a variety of ways of doing it ... depending on the language you're writing. Here are some hints: /abcd/i Perl - an i after the regular expression eregi PHP - use eregi rather than ereg re.I or re.IGNORECASE Python - extra parameters ...
2007-09-07
 
1305Regular expressions made easy - building from components
There seems to be a certain macho desire in many programmer's minds to write a single complicated regular expression to match against an input line, ignorning the structured approach that everyone accepts quite cheerfully in almost every other case. Have a look at this Python line: wholeline = r"\d\d-...-\d\d\d\d\s+(\d\d):(\d\d):(\d\d.\d\d),\s+(-?\d+\.\d+),\s+(-?\d+\.\d+),(-?\d+\.\d+),\s+(-?\d+\.\d+),(-?\d+\.\d+),\s+(-?\d+\.\d+)" Impressive, ...
2007-08-16
 
1043Sending an email from Python
Good question - came up on the course yesterday and all the examples I could find were longwinded or obfursacted to avoid them abusing the email addresses of the people named. At the risk of getting lots of people trying this out and filling my mail box, here is a sample piece of code that emails grom ...
2007-01-18
 
753Python 3000 - the next generation
There is no definite schedule for Python 3 (a.k.a. Python 3000 or Py3K) but a Python Enhancement Proposal (PEP) that details plans exists. There's a guiding principle to reduce duplication by removing old ways of doing things which will break version 2 compatibility. (Heard it before ... Perl 5 to Perl ...
2006-06-09
 
672Keeping your regular expressions simple
There's something macho about programmers when it comes to regular expressions - so often they'll try and do the whole job in a single regular expression when doing a two stage process is much more logical, much quicker in operation, and far easier to code. Take a requirement that came up this morning, ...
2006-06-05
 
Examples from our training material
again   Looking for part of a string that repeats later
bench.py   Find largest 5 files in or below a directory
class_v_static.py   Decorators - your own, plus @classmethod and @staticmethod
cli.py   Report on command line parameters
cpick   Store an object via cPickle
cunpick   recover a pickled object
curr27   From Python 2.7 - currency alternative
currency.py   Formatting a currency using Regular Expression
emma   Regular expression then split
eo2.py   Scanning log file for instability
flist.py   All the files in a directory - which is largest?
gad1.py   Create a Gadfly (SQL) database and insert data
gad2.py   Running an SQL query - Gadfly
get_os.py   Get Operating System information
hostfilter.py   Extract host computer information - strip comments with regular expressions
mar_in.py   Loading in an object saved via the marshal module
mar_out.py   Marshal converts an object to a string
myuser.py   class for use in pickle / unpickle demo
penv.py   Python environment variables
pocohunter   Looking for postcodes in a string
psplit   Splitting at a string v splitting at a regular expression
py_mysql.py   MySQL to Python using MySQL Connector
pysql_another   Using a MySQL database - select across multiple tables
python_mysql_web.py   Python, MySQL, CGI (Web) board
re1.py   Regular expression - first example
re2.py   Stripping spaces
re3.py   Find email addresses in line of text
re4.py   Regular expression split over several lines
refun   evaluating a net list in EQN format
relib.py   Some common regular expressions
retest.py   Regular Expression test engine
sql1.py   Hello MySQL World in Python
sql1a.py   MySQL to Python using MySQLdb
sqlite.py   Sqlite3 / Python 3 example
subp   Subprocess module - replacement for os.popen
syscommand   Running an operating system command in Python
tim   Some time handlers
timestuff.py   Some time handling
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 http://www.training-notes.co.uk.
Topics covered in this module
Is Python compiled or interpreted?.
Regular expressions in Python.
Elements of a Python-style regular expression.
Anchors (Assertions).
Literal characters.
Character groups.
Counts.
Alternation.
Grouping.
Modifiers.
Some examples.
Methods available on Python regular expressions.
Some more examples and features of regular expressions.
Some popular regular expressions.
Running Python and system commands from within.
Handling dates and times in Python.
Pickling and shelving.
Accessing the environment from Python.
Talking to SQL databases from Python.
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 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. Also available is the Opentalk Forum for discussion of technical questions.


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/resources/Y115.html • PAGE BUILT: Thu Sep 18 11:03:17 2014 • BUILD SYSTEM: WomanWithCat