Introduction to Scripting Languages: Python Some slides are based upon Python Documentation - Extended.

Slides:



Advertisements
Similar presentations
Introduction to Python LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Advertisements

10/10/1999© 1999 CNRI, Guido van Rossum 1 Python Workshop Guido van Rossum CNRI (Corporation for National Research Initiatives, Reston, Virginia,
Container Types in Python
Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Introduction to Python. Python is a high-level programming language Open source and community driven “Batteries Included” – a standard distribution includes.
What is a scripting language? What is Python?
Python Tidbits Python created by that guy ---> Python is named after Monty Python’s Flying Circus 1991 – Python Released 2008 – Python 2.6 / 3.0rc2.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
Scripting Languages CS 351 – Programming Paradigms.
C. Varela, Adapted with permission from Guido van Rossum1 Python Intro, Concurrency Carlos Varela RPI Adapted with permission from: Guido van Rossum
JaySummet IPRE Python Review 2. 2 Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing.
Writing Solid Code Introduction to Python. Program 1 python -c "print 'Hello World' “ python -c "import time; print time.asctime()“ Start an interactive.
 1 String and Data Processing. Sequential Processing Processing each element in a sequence for e in [1,2,3,4]: print e for c in “hello”: print c for.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Introduction to Python Guido van Rossum Director of PythonLabs at Zope Corporation
Introduction to Scripting Languages: Python Some slides are based upon Python Documentation - Extended.
Introduction to Python LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation (Now with: Google Inc.)
1 Programming in Python Language Overview. 2 Who is using it? Google (various projects) NASA (several projects) NYSE (one of only three languages "on.
Introduction to Python John Reiser May 5 th, 2010.
Extending Python with C (Part I – the Basics) June 2002 Brian Quinlan
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
The Python Programming Language Jeff Myers Programming Language Concepts, 01/14/2002
Python Tutorial Lecture for EE562 Artificial Intelligence for Engineers 1.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Python Lists and Such CS 4320, SPRING List Functions len(s) is the length of list s s + t is the concatenation of lists s and t s.append(x) adds.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Lists and Tuples Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Documentation / References Python Full Documentation – Python Quick Reference –
Built-in Data Structures in Python An Introduction.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction to Python LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation (Now with: Google Inc.)
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Python Basics Tom LeFebvre. Sept , 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
LECTURE 3 Python Basics Part 2. FUNCTIONAL PROGRAMMING TOOLS Last time, we covered function concepts in depth. We also mentioned that Python allows for.
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Introduction to Python Aug 22, 2013 Hee-gook Jun.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
11/04/2009 © 1999 CNRI, Guido van Rossum 1 Python Crash Course Original Document : Python Workshop
Python Bryce Boe.
Introduction to Python
An Introduction to Java – Part I, language basics
Introduction to Python
CS 180 Assignment 6 Arrays.
Basic String Operations
Introduction to Python LinuxWorld - New York City - January 2002
Programming in Python Language Overview
Lists Like tuples, but mutable. Formed with brackets: Assignment: >>> a = [1,2,3] Or with a constructor function: a = list(some_other_container) Subscription.
Presentation transcript:

Introduction to Scripting Languages: Python Some slides are based upon Python Documentation - Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014 Abed Asi

 C and Assembly – Efficient code with access to OS services  Shell Scripts – connecting Unix utilities by I/O redirection and pipes 2

 In practice, programs output needs pre-processing  Usually an interpreted scripting language  Useful for writing and maintaining:  custom commands for a command shell  wrapper programs for executables  C/Java VS. Python 3

4 import java.io.IOException; import java.io.FileReader; import java.io.BufferedReader; class numlines { public static void main(String[] args) throws IOException { BufferedReader inp = new BufferedReader(new FileReader(args[0])); String line; for(int i=1;;++i) { line = inp.readLine(); if(line==null) break; System.out.printf("%3d: %s\n", i, line); } inp.close(); } } import sys i = 1 for line in file(sys.argv[1]): print "%3d: %s" % (i, line), i+= 1

 An open source interpreted programming language  High-level language  Object-Oriented  Functional Programming  Suitable for scripting  Practical ( VS. Efficiency )  Dynamic language 5

 No need to declare  Not typed greeting = "hello world" greeting = 12**2 print greeting  Need to assign (initialize) ▪ use of uninitialized variable raises exception 6

 "hello"+"world" "helloworld"# concatenation  "hello"*3"hellohellohello" # repetition  "hello"[0]"h"# indexing  "hello"[-1]"o"# (from end)  "hello"[1:4]"ell"# slicing  len("hello")5# size  "hello" < "jello"1# comparison  "e" in "hello"1# search 7

[ ] >>> my_list = ['Hello', 1, 2.2, 'world'] >>> len(my_list) 4 >>> my_list[0] ‘Hello’ >>> my_list.append(‘espl’) >>> my_list >>> ['Hello', 1, 2.2, 'world‘,’espl’] >>> del my_list[0] [1, 2.2, 'world‘,’espl’] >>> my_list.index(‘espl’) >>> 4 >>> ‘espl141’ in my_list >>> False 8

 Hash tables, "associative arrays"  d = {"duck": "eend", "water": "water"}  Lookup:  d["duck"] -> "eend"  d["back"] # raises KeyError exception  Keys, values, items:  d.keys() -> ["duck", "back"]  d.values() -> ["duik", "rug"]  d.items() -> [("duck","duik"), ("back","rug")]  Presence check:  d.has_key("duck") -> 1; d.has_key("spam") -> 0 9

 key = (lastname, firstname)  point = (x, y, z) # parentheses optional  a,b,c = point # unpack  lastname = key[0]  sort of an immutable list TypeError: 'tuple' object does not support item assignment  key[1] = ‘Abed’ # TypeError: 'tuple' object does not support item assignment 10

def ( ): def factorial(n): fact = 1 for i in range(1, n): fact = fact * i return fact 11

class student: def __init__(self, id): self._id = id self._grades = {} def update_grade(self, subject, grade): self._grades[subject] = grade #Comment, Main: s = student(' ') s.update_grade('heshbon', 80) s.update_grade('handasa', 49) 12

>>> from math import * >>> sin(30*3.14/180) >>> from math import sin >>> sin(30*3.14/180) >>> from math import sin as sinus >>> sinus(30*3.14/180) 13

 Control structures  If statement  While  For  …. 14