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

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.
Ruby: An introduction - Who am I? Maciej Mensfeld Presented by: Maciej Mensfeld Ruby: An introduction dev.mensfeld.pl github.com/mensfeld.
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.
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.
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
Writing Solid Code Introduction to Python. Program 1 python -c "print 'Hello World' “ python -c "import time; print time.asctime()“ Start an interactive.
Unix Processes Slides are based upon IBM technical library, Speaking Unix, Part 8: Unix processes Extended System Programming Laboratory (ESPL) CS Department.
 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
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.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
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.
The Python Programming Language Jeff Myers Programming Language Concepts, 01/14/2002
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 –
Lists CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
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
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.
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.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
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 Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Introduction to Programming Oliver Hawkins. BACKGROUND TO PROGRAMMING LANGUAGES Introduction to Programming.
Introduction to Scripting Languages: Python Some slides are based upon Python Documentation - Extended.
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
CS 330 Class 7 Comments on Exam Programming plan for today:
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Introduction to Python
basic Python programs, defining functions
An Introduction to Java – Part I, language basics
Introduction to Python
CS 180 Assignment 6 Arrays.
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 2014/2015

2 When ?TopicLecture October 26, 2014 Introduction to C Programming in Unix Environment - I 1 November 2, 2014 Introduction to C Programming in Unix Environment - II 2 November 9, 2014Introduction to Assembly3 November 16, 2014Functions and System Calls (Assembly)4 Midterm A (December 9, :00) December 7, 2014Unix Processes5 December 14, 2014Programs Execution6 December 28, 2014Introduction to script languages (Python) + ELF 7 January 4, 2014Web programming8 Midterm B (January 19, 2015) OR (January 20, 2015)

3

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

 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 5

6 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 7

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

 "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 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

[ ] >>> 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 11

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

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

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) 14

>>> 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) 15

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