Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.

Slides:



Advertisements
Similar presentations
® ® Why Design Another Language? Python UK & ACCU Spring Conference Oxford - April 2, 2003 Guido van Rossum Director of PythonLabs at Zope Corporation.
Advertisements

"The State of the Python Union" Python10 - Alexandria, VA - February 7, 2002 Guido van Rossum Director, PythonLabs at Zope Corporation
Why I Invented Python EuroPython – June 27, 2005 Guido van Rossum Elemental Security, Inc.
State of the Python Union PyCon DC, March 26-28, 2003 Guido van Rossum Director of PythonLabs at Zope Corporation
CS 330 Programming Languages 10 / 11 / 2007 Instructor: Michael Eckmann.
Ruby The Gem of new programming languages. An interpreted scripting language.
Scripting Languages CS351 – Programming Paradigms.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
Jonathan Huelman CSC 415 – Programming Languages
Introduction to Python. What is Python? Interpreted object oriented high level programming language – No compiling or linking neccesary Extensible: add.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
CSC 9010: Natural Language Processing
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Introduction to Python Kris Kneubuhler SE NPUG July 17 th 2014.
Intro to Python Programming (Resources) Pamela A. Moore Zenia C. Bahorski Eastern Michigan University March 7, 2012 A language to swear by, not at. 1.
Automatic for the personnel “Librarian friendly programming” Dror Berger & Meirav Livne IGELU 2014.
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.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
General Programming Introduction to Computing Science and Programming I.
The Python interpreter CSE 140 University of Washington Michael Ernst.
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
Python 0 Some material adapted from Upenn cmpe391 slides and other sources.
Introduction to PythonIntroduction to Python SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar.
Python Modules An Introduction. Introduction A module is a file containing Python definitions and statements. The file name is the module name with the.
The Python Programming Language Jeff Myers Programming Language Concepts, 01/14/2002
Modules and Decomposition UW CSE 190p Summer 2012 download examples from the calendar.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
1 CSC 221: Introduction to Programming Fall 2012 Python data, assignments & turtles  Scratch programming review  Python & IDLE  numbers & expressions.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Python – May 11 Briefing Course overview Introduction to the language Lab.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
Python Functions.
Variables, Expressions and Statements
Compsci 06/101, Spring Compsci 6/101: PFTW, Feb 28-March 4 l Algorithms and Data Structures  Sets and how they are used in Python (data structure)
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
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.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python Karsten Hokamp, PhD Genetics TCD, 03/11/2015.
Head First Python: Ch 1. Everyone loves lists Aug 22, 2013 Hee-gook Jun.
Python Let’s get started!.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
REFERENCE: CHAPTER 1 High-level languages + Python.
Compsci 06/101, Fall Programming Equations l Algorithms + Data Structures = Programs  Niklaus Wirth, old view of programming and compsci l How.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 10th, 2009 Introduction to Programming.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/9/2006 Lecture 6 – String Processing.
Victoria Manfredi September 27, 2016.
Topic 2: Hardware and Software
Introduction to Java Import Scanner class to use in our program
Introduction to Computing Science and Programming I
Python Let’s get started!.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Natural Language Processing (NLP)
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
To Get Started Paper sheet
CS190/295 Programming in Python for Life Sciences: Lecture 1
Introduction to Python programming
Programming Tips GS540 January 10, 2011.
Natural Language Processing (NLP)
Review We've seen that a module is a file that can contain classes as well as its own variables. We've seen that you need to import it to access the code,
The Python interpreter
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Natural Language Processing (NLP)
Presentation transcript:

Python  Monty or Snake?

Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.

Why Python  Sysadmin acceptance  Right structures and system access  Obj-orient, and OS access  Interpret or compile?  Popularity trend 

Outcomes  Explain Python rationale  import this # for the Zen of python  Code in Python – for sysadmin  Command line (Python vs. Ipython  Python IDE (Eclipse/pydev – discuss)  Access Python Resources

Style  Perl:  There is more than one way to do it  (TIMTOWTDI)  Python:  There should be one– and preferably only one –obvious way to do it – Zen of Python  Although that way may not be obvious at first unless you’re Dutch  “clever” is NOT a compliment in Python

Prepare to code!  Python is built into Linux and OS X. Easy to install in Win  Python at command line  SDK: install Eclipse and Pydev  If you want Ipython in Ubuntu …  Look for Synaptic Package Manager (admin)  Search & install ipython

Lets Python  Open a terminal  Start ipython  In [1]:  Spam=6+2  print spam

Example  Import more.py in ipython  syntax (indentation)  loops, variables, data types, modules (library)

Python Characteristics  Multi-paradigm: structure- supported but not enforced  Object Oriented (objects, methods etc.)  Structured programming (a’ la Pascal)  functional programming etc. (evaluate fns, avoid states)  dynamic (but strong) typing and name resolution  syntax (indentation)  command line development  Python vs. IPython

Why IPython  Many reasons, see ch 2 is Linux Admin text  PLULSA by Gift and Jones  OS commands like ls and pwd and cd work in IPython but not in regular Python command-line

Libraries of modules  Access Libraries of modules. EG. the sys library  import sys  dir(sys)  sys.__doc__  Use the following example

Use a combination of IPython and Eclipse  Try out ideas in Ipython  If it doesn’t work on command line it won’t work work in a.py script file.  Then create the code in Eclipse

‘more’ demo  # A simple version of a 'more' function. R. Helps 2010, edited from a "Programming Python" example # Call this function with more(text_string) # Not an example of excellent code style. Done to show several aspects of Python def more(text, numlines=15): lines = text.split('\n') # split the text string into separate strings at the newline #.split method (function) defined for text objects. print lines # just for debug. See that the text string has been split count = 0 while lines: # loop through all the text strings # Notice the ':' and the (lack of) parentheses and the (strict) indentation chunk = lines[:numlines] # the :number 'slices' off a chunk # slice notation for text strings textstring[a:b] # omitting 'a' defaults to 0 (beginning of string) # omitting 'b' defaults to end-of-string lines = lines[numlines:] for line in chunk: count+=1 # count the lines we print print count,': ', line if lines and raw_input('More? ') not in ['y', 'Y']: # raw_input reads as text break print '===== End text======= Count=', count

Comments  Demo only intended as a discussion of features, not programming style  Many more library modules  See library link for morelibrary link  Try some of these.  Use dir(module) and  module.__DOC__ with your new more()

Scripting Philosophy  Create a small working core and then add features  Bad practice for large programs  Try out each idea on the command line first  If you can’t make ‘adduser’ work on the command line, it will never work in Python

Now do the tutorial  Tutorial  Ch 3-7  Also see the if __name__ == ‘__main__’ trick herehere

Assignments  HW: Work through the tutorial

The Zen of Python  Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one– and preferably only one –obvious way to do it. Although that way may not be obvious at first unless you’re Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea — let’s do more of those!