Introduction to Python

Similar documents
Java Application Deployment on the Web

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

Week - 01 Lecture - 04 Downloading and installing Python

Physics 514 Basic Python Intro

Linux Command Line Interface. December 27, 2017

MEIN 50010: Python Introduction

CSC 015: FUNDAMENTALS OF COMPUTER SCIENCE I

Getting Started with Python

Review of Fundamentals

How to Use Skype & Pamela Software to Record Your Podcast

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

These are exciting times for Macintosh users. When Apple unleashed Mac

C Programming. A quick introduction for embedded systems. Dr. Alun Moon UNN/CEIS. September 2008

Introduction to Computer Programming for Non-Majors CSC 2301, Fall The Department of Computer Science

Senthil Kumaran S

Hello! ios Development

Part III Appendices 165

Introduction to the Emacs Editor

Table of Contents EVALUATION COPY

Accelerating Information Technology Innovation

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

COPYRIGHTED MATERIAL. Installing Xcode. The Xcode Installer

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Lab 2 Building on Linux

Science One CS : Getting Started

EL2310 Scientific Programming

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

WIRELESS N USB ADAPTER USER MANUAL

EL2310 Scientific Programming

Using IDLE for

Before you dive into learning how to use Sage Timeslips, performing a

Using echo command in shell script

Introduction to Computer Programming for Non-Majors

seminar learning system Seminar Author and Learning System are products of Information Transfer LLP.

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

What Version Number to Install

Lab #2 Physics 91SI Spring 2013

Decisions, Decisions. Testing, testing C H A P T E R 7

Installing Python 3 on Your Personal Computer

Lab 1 Introduction to UNIX and C

Tcl/Tk for XSPECT a Michael Flynn

A Gentle Introduction to CMSC311 labs and CVS Or How I learned to use CVS in CMSC311. William Arbaugh September 2, 2004

Welcome to Python! If you re the type of person who wants to know

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Richard Mallion. Swift for Admins #TEAMSWIFT

Printing Envelopes in Microsoft Word

Python Programming Exercises 1

ASCII Art. Introduction: Python

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

FEATURES EASILY CREATE AND DEPLOY HIGH QUALITY TCL EXECUTABLES TO ANYONE, ANYWHERE

Creating an HTML file (Mac)

How To Get Your Word Document. Ready For Your Editor

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

CS 1110, LAB 1: PYTHON EXPRESSIONS.

Lab 1 Introduction to UNIX and C

T H E I N T E R A C T I V E S H E L L

CONVERSION TRACKING PIXEL GUIDE

QuickBooks 2008 Software Installation Guide

Customizing DAZ Studio

CptS 360 (System Programming) Unit 3: Development Tools

Python for Non-programmers

CMSC 201 Spring 2017 Lab 01 Hello World

CSC209. Software Tools and Systems Programming.

BCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer

4.7 Approximate Integration

Programming Assignment 3

CIS 086 : Week 1. Web Development with PHP and MySQL

CSC209. Software Tools and Systems Programming.

Python Input, output and variables

Zope and RDBMS. A beginner's guide to working with relational databases from Zope. EuroPython Conference 2007 Vilnius, Lithuania.

Chapter 2. Editing And Compiling

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

ONLINE EVALUATION FOR: Company Name

PHP 1. Introduction Temasek Polytechnic

Inside PHP Tom OSCON th July, 2012

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Getting Started with Python and the PyCharm IDE

CNT 5605, Fall 2009: Introduction

Silk Performance Manager Installation and Setup Help

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Project 1 Balanced binary

Microsoft Access 2010 VBA Programming Inside Out Free Ebooks PDF

Instructions. First, download the file

WHAT IS AN INTERNET BACKBONE? And what makes a good one?

CSCI 201 Lab 1 Environment Setup

CITS2401 Computer Analysis & Visualisation

shortcut Tap into learning NOW! Visit for a complete list of Short Cuts. Your Short Cut to Knowledge

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

B a s h s c r i p t i n g

Lab1: Communicating science

Basic Keywords Practice Session

A computer program is a set of instructions that causes a computer to perform some kind of action. It isn t the physical parts of a computer like the

Chapter 1. Preliminaries

Ubuntu Install Instructions Macbook Pro >>>CLICK HERE<<<

What is the Best Way for Children to Learn Computer Programming?

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Robert Recorde room Swansea, December 13, 2013.

CMSC 201 Spring 2018 Lab 01 Hello World

Mr G s Java Jive. #11: Formatting Numbers

Making the case for SD-WAN

Transcription:

A sample Training Module from our course WELL HOUSE CONSULTANTS LTD 404, The Spa Melksham, Wiltshire SN12 6QL United Kingdom PHONE: 01225 708225 FACSIMLE 01225 707126 EMAIL: info@wellho.net 2004 Well House Consultants Ltd., all rights reserved written by Graham J. Ellis 191 1 Introduction to Python This module introduces the Python programming language. It s written for readers with some prior programming knowledge who are looking to learn about Python for use in their work. What is Python?.......................................... 2538 Running Python from the command line......................... 2538 Running Python from a file - "Hello Python World"................. 2538 Obtaining and installing Python............................... 2539 Python versions........................................... 2543 What is Python good for?................................... 2543 Where did the Python name come from?........................ 2543 Well House Consultants Samples Introduction to Python 2537

Y101 191.1 What is Python? Python is a programming language. It s available at no charge and it runs on many different platforms. It has a simple syntax, and yet it can be used for a wide range of applications. 191.2 Running Python from the command line Python is a scripting language. That means that you can enter your commands into a plain text file and run them straight from that file without the need for any intermediate conversion into "object files", "class files" or "executable files. It also means that you can call python from the command line, enter commands one-by-one, and have them execute right away. coffee% python Python 2.3 (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> base = 20 >>> height = 35.72 >>> area = base * height >>> print area 714.4 >>> ^D coffee% You ll notice that Python can be written one command per line, that variables can be used without being declared, and that there s no ";" or "." character to indicate the end of a command all subjects which we ll study in much more detail later. To exit from Python, we entered control-d on the keyboard. That s the end-offile character on our computer, "coffee", and is running a Unix/Linux/Mac OSX operating system. The ^D you see in the example above is how the operating system echoes the input. On windows boxes, the end-of-file is control-z. 191.3 Running Python from a file - "Hello Python World" You won t want to type your instructions (program) in every time, so you can edit your commands into a plain ASCII text file and run the program from that file: coffee% python hello.py Hello Python World 528.6 coffee% There s no need for the file to have a name ending in.py if you re going to run it in this way, but it s a convention and it makes it easier later on when you don t want to have to type "python" in front every time. Use any ASCII text editor you like, from Ultraedit to Notepad on a Windows operating system, vi or emacs under Unix or Linux, or on textedit under OSX. The important thing to remember is that you must save it as plain ASCII text! Our file hello.py contained: print "Hello Python World" base = 30 height = 17.62 area = base * height print area 2538 Introduction to Python Well House Consultants, Ltd.

Chapter 1 191.4 Obtaining and installing Python You may be lucky. If you re running an operating system such as Linux, Python will come as part of the distribution and may already be installed and ready to go. If you re using Python on your web site, hopefully you ll have chosen an ISP that supports the language; in which case it will be already installed. If Python isn t on your system, a copy on a CD might in the back of Python books. But the best method, because it will always be the most current version available, would be to download a copy from the web. Downloading from www.python.org The "Official" version of Python may be found at www.python.org and it s an easy download Figure 946 Here s the site s front page; it s dynamic, so you ll find that by the time you re reading these notes version numbers and news will have moved on. Figure 947 The download button takes you to the release page, where you choose which release you want, which takes you to the download page itself where you select the version most appropriate for your operating system. Well House Consultants Samples Introduction to Python 2539

Y101 Once you ve downloaded Python, installation instructions will vary depending on your operating system. In most cases, installing Python is no different to installing other downloaded software. Downloading from ActiveState An alternative download of Python, which includes commonly used external modules such as Expat for XML handling and (in the Windows version) some Windows extensions. See http://www.activestate.com. Figure 948 An alternative download of Python 2540 Introduction to Python Well House Consultants, Ltd.

Chapter 1 Downloading from Plone If you re going to be using Python as a component part of an application or system, you ll probably wish to download it as part of that application. For example, if you re going to be using the Plone Content Management System, which is built on the Zope application server, which in turn uses Python, you can simply download everything from the Plone site - http://plone.org. Figure 949 Downloading from Plone Well House Consultants Samples Introduction to Python 2541

Y101 Once you ve installed your complete system, it should use Python without further setup; if you want to use Python directly, sure, go ahead: C:\Program Files\Plone 2\Python>python Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> stock = 20 >>> price = 17.6 >>> value = stock * price >>> print value 352.0 >>> ^Z C:\Program Files\Plone 2\Python> You can also associate the Python program with files with a.pl extension so that you can make direct use of the language, for example: C:\DOCUME~1\trainee>type fred.py print "hello world" C:\DOCUME~1\trainee>fred.py hello world C:\DOCUME~1\trainee> 2542 Introduction to Python Well House Consultants, Ltd.

Chapter 1 191.5 Python versions The current (April 2004) version of Python is version 2.3.3. If you re already running a version 2.3, there s no need to upgrade. If you re running version 2.2, we suggest that you don t upgrade unless you have some very specific reason to do so. If it ain t bust, don t fix it! Version 2.2 introduced a new object model that will be useful in many larger and more complex systems. If you re writing such a system under Python 2.1 or older, you should consider upgrading. Do remember that if you use the new object model in your code, that code will then only run on systems running version 2.2 or later, which might be a consideration if you re going to put your live system (or a copy of it) onto a computer for which you are not the administrator, and which may be running an old version Currently downloadable versions on www.python.org Python 2.3.3 (December 19, 2003) Python 2.2.3 (May 30, 2003) Python 2.1.3 (April 8, 2002) Python 2.0.1 (June 2001) Python 1.6.1 (September 2000) Python 1.5.2 (April 1999) 191.6 What is Python good for? There are a lot of languages out there, so why choose Python against Java or PHP or Perl or C or...? Python is a superb object oriented language that makes it ideal for large projects where coding is going to be shared between a number of people, and typically you ll be talking about a suite of applications rather than a single program. Arguably, Object Oriented programming is harder to learn but more efficient to write, alter and maintain in the longer run for larger projects. Typically, the staff involved in writing your Python programs will be computer professionals rather than people who spend only a few percent of their time programming. There is no complex compile and load cycle with Python, so it s ideal for scientific experimental work (and prototyping) where the code will be changed frequently. And if you produce a superb prototype, you ll often find that there is no need to then rewrite your application into C / C++ / C# / Java / some other language the prototype will become the production code! 191.7 Where did the Python name come from? "And now for..." Well House Consultants Samples Introduction to Python 2543

Y101 191.8 Other resources Python is a great embedding language we ve already seen reference to Zope and Plone, and there are many more! The Vaults of Parnassus http://www.vex.net/parnassus/ is your starting point: Figure 950 The Vaults of Parnassus Here are some of the most recently updated offerings: 2544 Introduction to Python Well House Consultants, Ltd.