Python 0 Some material adapted from Upenn cmpe391 slides and other sources.

Slides:



Advertisements
Similar presentations
Chapter One The Essence of UNIX.
Advertisements

Learn Python in three hours
Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.
Python Brandon Jeffcoat Dashaun West “Why settle for snake oil when you can have the whole snake?” -- From Usenet posting by Mark Jackson, June 1998.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Python Jordan Miller and Lauren Winkleman CS 311 Fall 2011.
Scripting Languages CS351 – Programming Paradigms.
Scripting Languages. Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make.
Guide To UNIX Using Linux Third Edition
Introduction to Python: Slides Referenced in Homework 0 CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth January 2005.
Python Introduction.
TOPIC 5.0 LINUX SHELLS.
CSC 110 A 1 CSC 110 Introduction to Python [Reading: chapter 1]
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 2 Fundamentals of Programming Languages 4/5/09 Python Mini-Course: Day.
CS110/CS119 Introduction to Computing (Java)
Intro to Python Programming (Introduction) Pamela A. Moore Zenia C. Bahorski Eastern Michigan University March 7, 2012 A language to swear by, not at.
Computer Science 111 Fundamentals of Programming I Overview of Programming.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Python From the book “Think Python”
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
FLUKA GUI Status FLUKA Meeting CERN, 10/7/2006.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Python I Some material adapted from Upenn cmpe391 slides and other sources.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Python – May 11 Briefing Course overview Introduction to the language Lab.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
Introduction to Python Origins Nature of Python Importance of Python Example.
DrJava A lightweight pedagogic environment for Java Eric Allen, Robert Cartwright, and Brian Stoler Rice University
Installing and Developing Programs in Python. Installing Python is pre-installed on most Unix systems, including Linux and MAC OS X The pre-installed.
Installing and Developing Programs in Python. Installing Python is pre-installed on most Unix systems, including Linux and MAC OS X The pre-installed.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.
Python I Some material adapted from Upenn cmpe391 slides and other sources.
A Python Tour: Just a Brief Introduction "The only way to learn a new programming language is by writing programs in it." -- B. Kernighan and D. Ritchie.
Exploring Spyder: An IDE for scientific computing
Xi Wang Yang Zhang. 1. Easy to learn 2. Clean and readable codes 3. A lot of useful packages, especially for web scraping and text mining 4. Growing popularity.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Learning Unix/Linux Based on slides from: Eric Bishop.
Python Joseph Eckstrom, Benjamin Moore, Willis Kornegay.
Programming C++ in Linux by various IDEs and editors by: Danial Khashabi Master: Dr.B.Taheri November 2008.
Fundamentals of Programming I Overview of Programming
Python Programming Unit -1.
Development Environment
CST 1101 Problem Solving Using Computers
Unix Scripting Session 1 March 6, 2008.
A Python Tour: Just a Brief Introduction
PowerShell Introduction Copyright © 2016 – Curt Hill.
Python: Experiencing IDLE, writing simple programs
ITCS-3190.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Lecture 11 bash scripting overview c programming overview moving data between c and bash memory and pointers.
basic Python programs, defining functions
Do you know this browser?...
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Python I Some material adapted from Upenn cmpe391 slides and other sources.
Introduction to Python
Python I Some material adapted from Upenn cmpe391 slides and other sources.
basic Python programs, defining functions
Introduction to Python
Introduction to programming with Python
Compilers and Interpreters
12th Computer Science – Unit 5
Chapter 1: Programming Basics, Python History and Program Components
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Presentation transcript:

Python 0 Some material adapted from Upenn cmpe391 slides and other sources

Overview History Significance Installing & Running Python Simple script examples

Brief History of Python Invented in the Netherlands, early 90s by Guido van Rossum Named after Monty Python Open sourced from the beginning, man-aged by Python Software Foundation Considered a scripting language, but is much more Scalable, object oriented and functional from the beginning Used by Google from the beginning

Python’s Benevolent Dictator For Life “Python is an experiment in how much freedom program-mers need. Too much freedom and nobody can read another's code; too little and expressive-ness is endangered.” - Guido van Rossum

Python’s place in the Market TIOBE has been collecting data on programming language “popularity” for many years Counts results for a query like "<language> programming” on popular search engines 10/10 TIOBE Programming Community Index

http://python.org/

http://docs.python.org/

The Python tutorial is good!

Running Python

The Python Interpreter Typical Python implementations offer both an interpreter and compiler Interactive interface to Python with a read-eval-print loop [finin@linux2 ~]$ python Python 2.4.3 (#1, Jan 14 2008, 18:32:40) [GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def square(x): ... return x * x ... >>> map(square, [1, 2, 3, 4]) [1, 4, 9, 16] >>>

Installing Python is pre-installed on most Unix systems, including Linux and MAC OS X The pre-installed version may not be the most recent Two “latest versions” 2.7 released 7/10 & 3.2 released 10/10 Python 3 is a non-backward compatible version which you should not use for 331 Download from http://python.org/download/ Python comes with a large library of standard modules

Python IDEs and Shells There are many Integrated Development Environments IDLE Eclipse + PyDev Emacs As well as enhanced shells

IDLE Development Environment IDLE is the “official” IDE distributed with Python Preinstalled on MAC OS X Written in Python with the Tkinter GUI package Multi-window text editor with syntax highlighting, auto-completion, smart indent and other features Python shell with syntax highlighting, line recall, … Integrated debugger with stepping, persis- tent breakpoints, and call stack visi- bility

Eclipse + Pydev Pydev is an Eclipse plugin for Python Download from http://pydev.org/ Syntax highlighting, code completion, goto function, debugger, …

Editing Python in Emacs Emacs python-mode.el has good support for editing Python, enabled enabled by default for .py files Features: completion, symbol help, eldoc, and inferior interpreter shell, etc.

Emacs as a Python IDE You can fire up a shell in emacs via M-x python-shell You can also set up a more powerful Python IDE environment in EMACS Pymacs allows two-way communication between Emacs Lisp and Python Ropemacs provides advanced features such as completion, refactoring, etc

Running Interactively on UNIX % python >>> 3+3 6 Python prompts with ‘>>>’. To exit Python (not Idle): In Unix, type CONTROL-D In Windows, type CONTROL-Z + <Enter> Evaluate exit()

Running Programs on UNIX Call python program via the python interpreter % python fact.py Make a python file directly executable by Adding the appropriate path to your python interpreter as the first line of your file #!/usr/bin/python Making the file executable % chmod a+x fact.py Invoking file from Unix command line % fact.py

Example ‘script’: fact.py #! /usr/bin/python def fact(x): if x == 0: return 1 return x * fact(x - 1) print "\nN fact(N)" print "---------” for n in range(10): print n, fact(n)

Python Scripts When you call a python program from the command line the interpreter evaluates each expression in the file Familiar mechanisms are used to provide command line arguments and/or redirect input and output Python also has mechanisms to allow a python program to act both as a script and as a module to be imported and used by another python program

Another Script Example #! /usr/bin/python """ reads text from stdin and outputs any email addresses it finds, one to a line """ import re from sys import stdin # a regular expression for a valid email address pat = re.compile(r'[-\w][-.\w]*@[-\w][-\w.]+[a-zA-Z]{2,4}') for line in stdin: for address in pat.findall(line): print address

results python> python email0.py <email.txt bill@msft.com gates@microsoft.com steve@apple.com python>

Getting a unique, sorted list import re from sys import stdin pat = re.compile(r'[-\w][-.\w]*@[-\w][-\w.]+[a-zA-Z]{2,4}’) # found is an initially empty set (a list w/o duplicates) found = set() for line in stdin: for address in pat.findall(line): found.add(address) # sorted() takes a sequence, returns a sorted list of its elements for address in sorted(found): print address

results python> python email2.py <email.txt bill@msft.com gates@microsoft.com steve@apple.com python>

Conclusion: Python is .. Popular as a scripting language Popular as a general purpose language Open sourced Interesting from a program language perspective Easy to learn and use, so being used in many CS 101 courses