What is a scripting language? What is Python?

Slides:



Advertisements
Similar presentations
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Advertisements

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.
Chapter 6 Lists and Dictionaries CSC1310 Fall 2009.
Programming Languages and Paradigms The C Programming Language.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Python By Steve Wright. What is Python? Simple, powerful, GP scripting language Simple, powerful, GP scripting language Object oriented Object oriented.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to Python. Outline Python IS ……. History Installation Data Structures Flow of Control Functions Modules References.
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
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.
Scripting with Ruby What is a scripting language? What is Ruby?
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Writing Solid Code Introduction to Python. Program 1 python -c "print 'Hello World' “ python -c "import time; print time.asctime()“ Start an interactive.
Introduction to Python Guido van Rossum Director of PythonLabs at Zope Corporation
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Introduction to Python John Reiser May 5 th, 2010.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
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
H3D API Training  Part 3.1: Python – Quick overview.
Introduction to Python September 26, /10/ Bioinformatics Languages Low-level, compiled languages: C, C++, Java… Pros: performance Cons:
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
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.
If statements while loop for loop
Built-in Data Structures in Python An Introduction.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Getting Started with Python: Constructs and Pitfalls Sean Deitz Advanced Programming Seminar September 13, 2013.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Scripting with Ruby What is a scripting language? What is Ruby?
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
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.
Scripting with Ruby What is a scripting language? What is Ruby?
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
A Tutorial on the Python Programming Language. Overview Running Python and Output Data Types Input and File I/O Control Flow Functions.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Python Files and Lists. Files  Chapter 9 actually introduces you to opening up files for reading  Chapter 14 has more on file I/O  Python can read.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
PHP using MySQL Database for Web Development (part II)
Learning Basic Python Amlan Talukder.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Introduction Python is an interpreted, object-oriented and high-level programming language, which is different from a compiled one like C/C++/Java. Its.
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
CHAPTER THREE Sequences.
CS190/295 Programming in Python for Life Sciences: Lecture 6
PHP.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Python Primer 1: Types and Operators
PHP an introduction.
General Computer Science for Engineers CISC 106 Lecture 03
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Learning Python 5th Edition
Presentation transcript:

What is a scripting language? What is Python? Scripting with Python What is a scripting language? What is Python?

Scripting Languages Originally, a script was a file containing a sequence of commands that needed to be executed Control structures were added to make it possible to do more with scripts

Characteristics of Scripting Languages Generally interpreted Dynamic typing - no declarations Make text processing easy Often provide pattern matching for strings Provide file and directory manipulation Make it easy to do things quickly

Basic Scripting Languages Unix and Linux come with shell programs which are programmable sh bash ksh csh DOS had BAT files

Scripting in Other Environments Even with a GUI operating system, it is still useful to be able to automate repetitive tasks Windows still has bat files Mac OS has AppleScript Some applications have a scripting language built into them Microsoft applications have Visual Basic for Applications (VBA)‏ Hypercard (Apple) had HyperTalk

Other Scripting Languages Other scripting languages were developed to provide increased capability sed -- adapted from the UNIX ed editor in 1977 AWK -- created by Ajo, Wienberger and Kernighan in 1977 Tcl -- an extensible scripting language written by John Ousterhout in 1987 Perl -- created by Larry Wall in 1986 Python-- created in 1989 by Guido van Rossum Ruby -- created in 1993 by Yukihiro Matsumoto

Scripting and the Web More recently, a number of scripting languages have been developed for use with web browsers PHP JavaScript ASP (part of Microsoft .NET framework)‏

Scripting on onyx the shell languages sed awk perl python ruby tcl javascript php

Python An object-oriented scripting language Portable (written in ANSI C)‏ Powerful - see next slide Mixable - can be used in conjunction with other languages Easy to use Easy to learn

The Power of Python dynamic typing built-in objects built-in tools built-in libraries garbage collection modular

Running Python code Run the python interpreter and type the commands in interactively Call the interpreter with the name of the script python progName Type the program name of an executable script file chmod +x script ./script The first line of the script should be #!/usr/bin/python

Hello World #!/usr/bin/python import sys sys.stdout.write("Hello world!\n")‏

Python Program Structure A python program is composed of modules A python module is composed of statements statements are terminated by a newline unless the last character is a \ or there is an unclosed (. [ or { Put two statements on a line with a ; between Statements create and process objects

Python Built-in Types Numbers (immutable)‏ Sequences - indexing, slicing, concatenation Strings (immutable)‏ Lists (mutable)‏ Tuples (immutable)‏ Mapping - indexing by key Dictionaries (mutable)‏ Files

Numbers Numeric types integers - a C long long integer - arbitrary number of digits floating point - C double complex Standard arithmetic, comparison, bitwise operators plus ** (exponentiation)‏ Built-in functions : pow, abs, … Modules : rand, math, cmath

Sequences Strings : 'abc', "def", """triple-qouted for multi-line strings""" Lists : [1, 2, 4] Tuples : (1, 2, 3)‏

Sequence Operations concatenation with + indexing with [ ] slicing (substring) with [ : ] len( s) to get length % for formatting : fmtString % string * for repeating in for membership : 'a' in str

Strings Immutable, ordered sequences of characters Supports all sequence operations (see strings.py)‏ string module provides other functions re module supports pattern matching

string module Names must be qualified with the module name (string. )‏ upper(str), lower(str) - returns a string find( str, substr) returns index of substr split( str, delimStr=" ") returns list of string join( strList, separator) returns a string

String class As objects, strings have may of the same methods that the string module contains Qualify the methods with the name of the string

Lists Ordered collection of arbitrary objects arrays of object references mutable variable length nestable Representation : [0, 1, 2, 3] list methods modify the list (append, sort)‏ see lists.py

Tuples Ordered sequence of arbitrary objects Immutable Fixed length Arrays of object references Representation : (1, 2, 3)‏ Like lists except no mutations allowed

Dictionary Unordered collection of arbitrary objects Element access by key, not index (hash table)‏ Variable length, mutable nestable Representation : {'spam' : 2, 'eggs' : 3} see dict.py

Dictionary operations element access : d[key] insert, update : d[key] = 'new' remove : del d [key] length: len(d)‏ methods has_key( str)‏ keys() returns list of keys values() returns list of values

Boolean Expressions Expression truth values 0, "", [], {}, 0.0, None are all false everything else is true Comparison operators: < <= == != >= > return True and False (1 and 0)‏ Python allows a < b < c Boolean operators: and or not return an object which is true or false

Comparison == checks for value equivalence is checks for object equivalence < <= > >= do element by element comparison think of how strings are compared in Java

Python Statements Assignment Function calls print if/elif/else for/else while/else Def, return import, from break, continue pass - no-op try-except-finally raise (exception)‏ class global del - delete objects exec

Assignment Variable names follow the same rules as in C Names are created when they are first assigned Names must be assigned before they can be referenced Assignment creates an object reference Associativity is right to left

Assignment examples spam = 'spam' spam, ham = 'yum', 'YUM' list = [1, 2, 3] tuple = ('a', 'b', 'c')‏ d = {1 : 'one', 2 : 'two', 3 : three}

Blocks Blocks in python are started by a compound statement header : stmt1 … laststmt Blocks terminate when the indentation level is reduced

if Syntax else and elif are optional Can have arbitrary number of elif if test1: block1 elif test2: block2 else: elseblock else and elif are optional Can have arbitrary number of elif

while Syntax while test: loopbody else: nobreakaction Optional else part is executed if loop exits without a break break and continue work as in Java pass is a null statement used for empty body

for for loop is a sequence iterator works on strings, lists, tuples range is a function that generates a list of numbers for var in seq loopbody else: nobreakaction

Functions Define with def fun(p1, p2): return p1 + p2 Call with Function without a return statement returns None Names are local unless declared global Variables are references assigning to a parameter does not change the caller changing a mutable object does change the caller

Scope Python has three scopes local (in function)‏ global (in module)‏ built-in Nested functions do not have nested scope

os Module Provides a portable way to do OS- dependent operations manipulating files and directories listdir( path) mkdir( path) chmod( path, mode) process management fork, exec, kill system( command) system information