Programming in Python

 Home / MG2I-C0107
Programming in Python

Course Rationale

This unit has been designed to teach learners the fundamentals of scripting for the purposes of automation and 
development. These skills will be required in a variety of applications including scripting automated solutions to
common problems, developing server-side or desktop applications as well web applications. The unit also focuses
on automation by demonstrating and practicing the execution of external programs from the script created, as well
as the scheduling of tasks for a variety of purposes.

Pre-Requisites

The learner should have these skills or prior knowledge to be able to follow the course with success, however if entry
requirements are satisfied admission into the course will still be allowed.
General computer skills. Knowledge of some programming background can help too.

Unit Description

In this module Python is used as the reference scripting language, however the criteria for this unit have been
specified in such a way as to be applicable to any scripting language. The unit assumes no prior knowledge of
programming/scripting, or Python.

An introduction is given to the concepts of programming, particularly as
contrasted with scripting. The scripting language will then be introduced and basic concepts such as variables,
conversions, expressions, statements and functions will be covered. Following these basics, conditionals and
iterations will be introduced to cover the basic structure of a procedural program.

For data storage, strings and files
will be covered with a particular focus on file manipulation – a common task in automation scripts. Scripting
language specific features are also covered, including fruitful functions, lists, dictionaries and how to use tuples. A
number of practical tasks can be associated with this module, including taking system backups, retrieving data from
the Internet periodically, checking log files and so on.

Learning Outcomes

On completion of this unit the student will be able to:

1. Explain an approach to programming to be able to solve common automation problems, and how scripting
languages fit into this approach.

2. Use the scripting language to build desktop/console applications to automate common tasks.

3. Use the scripting language to execute external applications on the installed computer system as well as to
schedule tasks to be run at specific intervals.

4. Build basic web applications for remote control of automated tasks.

Unit Content

1. Explain an approach to programming to be able to solve common automation
problems, and how scripting languages fit into this approach.

1.1.Describe different paradigms for application development. 
1.1.1. Procedural. 
1.1.2. Functional. 
1.1.3. Object-Oriented.

1.2.Introduction to scripting. 
1.2.1. Using batch files. 
1.2.2. Using shell scripts. 
1.2.3. Scheduled tasks and cron jobs. 

1.3.Compare and contrast different scripting languages. 
1.3.1. Chosen language versus batch files/shell scripts. 
1.3.2. Chosen language versus other languages (such as Python/Perl/Java/PHP).

1.4.Prepare a workstation for Python development. 
1.4.1. Install Python. 
1.4.2. Install any libraries as specified by the lecturer. 
1.4.3. Install a web server suite for testing the basic web page with script integration. 
1.4.4. Install an IDE.

2. Use the scripting language to build desktop/console applications to automate common tasks.

2.1.Get started with the scripting language. 
2.1.1. How the interpreter works. 
2.1.2. “Hello, World!” in the chosen language.

2.2.Data types. 
2.2.1. Standard data types. 
2.2.2. Numbers and strings. 
2.2.3. Lists, tuples and dictionaries. 
2.2.4. Assignment statements. 
2.2.5. Formatting Strings. 
2.2.6. Introducing libraries.

2.3.Statements and syntax. 
2.3.1. Different statement types. 
2.3.2. Conditional statements. 
2.3.3. Looping statements.

2.4.Functions and generators. 
2.4.1. Creating functions. 
2.4.2. Variable scope. 
2.4.3. Nested functions. 
2.4.4. Arguments.

2.5.Modules and packages. 
2.5.1. Documentation. 
2.5.2. Comments. Page | 7 
2.5.3. Creating and using modules. 
2.5.4. Namespaces. 
2.5.5. Creating packages.

2.6.Exception handling 
2.6.1. Catching exceptions. 
2.6.2. Raising exceptions.

2.7.Interactive applications 
2.7.1. Overview of interactive applications. 
2.7.2. Building a simple interactive application.

2.8.Web applications. 
2.8.1. Overview of HTML. 
2.8.2. Creating a simple web page with script integration.

3. Use the scripting language to execute external applications on the installed computer system as well as to schedule tasks to be run at specific intervals. 
3.1.Persistence 
3.1.1. Reading and writing data to and from files. 
3.1.2. Saving data to files and loading data from files. 
3.1.3. Common saving formats for logs.

3.2.List comprehension. 
3.2.1. Using lists to enumerate files and entries.

3.2.2. List operations such as search, sort and arithmetic.

3.3.Functions 
3.3.1. Indirect function calls. 
3.3.2. Anonymous functions. 
3.3.3. Generator functions (if using Python or a supported language).

3.4.Documentation 
3.4.1. Using a documentation generator (such as pyDoc or Javadoc) to create technical documentation for easier maintenance.

3.5.Exception handling 
3.5.1. Raising exceptions. 
3.5.2. Raising exceptions and showing friendly error messages to the user.

3.6.Shell execution. 
3.6.1. Executing programs from the computer being used. 
3.6.2. Sending input to the programs. 
3.6.3. Getting output from the programs. 
3.6.4. Adding a scheduled task.

3.7.Web 
3.7.1. Creating a simple web interface to control scripts. 
3.7.2. Setting script permissions.

4. Build basic web applications for remote control of automated tasks. Page | 8 
4.1.An introduction to web programming. 
4.1.1. Overview of the client/server model. 
4.1.2. Overview of client-side technologies (HTML, CSS, JavaScript). 
4.1.3. Overview of the chosen language’s web-based capabilities.

4.2.HTTP 
4.2.1. Understanding the stateless web. 
4.2.2. HTTP Request and HTTP Response. 
4.2.3. Using the chosen language to handle HTTP Request and HTTP Response.

4.3.Controlling scripts 
4.3.1. Building a web application to control scripts on the target machine.

Assesment Method

This is a skills-based unit where learners are required to demonstrate they have they have the skills to be
able to use Python competently and as a consequence a large number of practical teaching strategies should be
adopted. The instructor should use as many hands-on and practical sessions as possible to ensure learners can work
effectively and efficiently to produce the ‘headless’ scripts, console-based applications, desktop applications and
web applications.

At this level it is essential that learners be exposed to lectures, discussions and presentation
contact hours to enable them to gain an in-depth knowledge and understanding of scripting. Practice should be
project-based whereby learners use Python to come up with scripts that automate everyday tasks. This may also
include the development of an interactive application to configure the script, and/or a web application to control it
remotely. Throughout the unit learners should be encouraged to develop logical thinking skills and to practice
stepwise refinement.

Learners should be encouraged to take responsibility for initiating and completing tasks and
should be encouraged to carry out individual research to consolidate and enhance their knowledge, understanding
and skills in a business application development context. As a consequence reference to real life business
requirements should permeate the unit. At this level learners should exercise autonomy and judgement within
limited parameters.

Suggested Activities: Examination 1.5 The written assessment should include a mix of short-answer or multiple-
choice questions related to the learning outcomes. Learners should demonstrate competence in all sections of the
assessment. The assessment should avoid asking learners to write hand-written code, instead knowledge of syntax
and, more importantly, general concepts should be asked in multiple-choice format. The assessment should be
supervised.

A practical assessment involving at least 30 hours of work. This should be an interactive application where the user can configure parameters for a script (for example, a backup script). The application will then generate the script and also provide options for scheduling the script to run.

As an alternative to a desktop interactive application, a web application can be built instead. The assessment should be presented together with a short document detailing system requirements, installation guide and a visual guide of the application features and pages.

js files