Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions.

Slides:



Advertisements
Similar presentations
1 Week 2 Questions / Concerns Schedule this week: Homework1 & Lab1a due at midnight on Friday. Sherry will be in Klamath Falls on Friday Lexical Analyzer.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
CS 206 Introduction to Computer Science II 01 / 20 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 14 / 2009 Instructor: Michael Eckmann.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
CS 206 Introduction to Computer Science II 09 / 09 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 21 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 04 / 2008 Instructor: Michael Eckmann.
Tuesday, December 05, 2006 I hear and I forget, I see and I remember, I do and I understand -Chinese Proverb.
CS 299 – Web Programming and Design Overview of JavaScript and DOM Instructor: Dr. Fang (Daisy) Tang.
Guide To UNIX Using Linux Third Edition
CS 206 Introduction to Computer Science II 01 / 23 / 2009 Instructor: Michael Eckmann.
The Scanner Class and Formatting Output Mr. Lupoli.
Regular Expressions. String Matching The problem of finding a string that “looks kind of like …” is common  e.g. finding useful delimiters in a file,
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
Pattern matching with regular expressions A common file processing requirement is to match strings within the file to a standard form, e.g. address.
Programming for Linguists An Introduction to Python 24/11/2011.
Lists in Python.
Munster Programming Training
Python – May 17 Recap lab Multidimensional list Exceptions Commitment: quiz tomorrow.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Python – May 11 Briefing Course overview Introduction to the language Lab.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
AP Comp Sci A Chapter 12 - Arrays. Ch 12 Goals: Goals: Declare and create arrays Declare and create arrays Access elements in arrays Access elements in.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Winter 2006CISC121 - Prof. McLeod1 Last Time Misc. useful classes in Java: –String –StringTokenizer –Math –System.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
FLEX Fast Lexical Analyzer EECS Introduction Flex is a lexical analysis (scanner) generator. Flex is provided with a user input file or Standard.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Lab 2 Primer Assignment 3 Structure File I/O More parsing and HTTP Formatting.
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 11 / 2009 Instructor: Michael Eckmann.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
Reviewing for Exam Lecture 12. Lab 1 Postfix.java –Hexadecimal Converting ‘a’ to number Converting ‘1’ to number –System.exit(3); Questions?
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
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.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
 Packages:  Scrapy, Beautiful Soup  Scrapy  Website  
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
Programming Fundamentals. Today’s Lecture Array Fundamentals Arrays as Class Member Data Arrays of Objects C-Strings The Standard C++ string Class.
C is a high level language (HLL)
String Handling. In C C has no actual String type Convention is to use null-terminated arrays of chars char str[] = “abc”; ‘a’, ‘b’, ‘c’, ‘\0’ String.h.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
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.
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
Today… Style, Cont. – Naming Things! Methods and Functions Aside - Python Help System Punctuation Winter 2016CISC101 - Prof. McLeod1.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
Lists/Dictionaries. What we are covering Data structure basics Lists Dictionaries Json.
Introduction to Programming (CS 201) Lecture 01 - Introduction.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
CSE 374 Programming Concepts & Tools
Whatcha doin'? Aims: To start using Python. To understand loops.
Regular Expressions Upsorn Praphamontripong CS 1110
CSC 458– Predictive Analytics I, Fall 2017, Intro. To Python
Perl Programming Language Design and Implementation (4th Edition)
Input and Output in Java
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CSC 458– Predictive Analytics I, Fall 2018, Intro. To Python
Input and Output in Java
Input and Output in Java
CS201 Fall 2016 George Koutsogiannakis
Python Basics with Jupyter Notebook
Lab 8: Regular Expressions
Exam # 1 INFORMATION Scheduled for Thursday 7/20
Presentation transcript:

Python – May 16 Recap lab Simple string tokenizing Random numbers Tomorrow: –multidimensional array (list of list) –Exceptions

Review To see both code & I/O: Window  Tile If your program has functions, how does the interpreter know where your program starts? When you write a loop with range: for i in range (1, 10) –i retains its last value after the loop (9) Look up something? Documentation: Python Standard Library, see “index” Link at top right of page.

Tokenizing Important skill in reading text input –Input file may be in specific format Two techniques –String’s split( ) function –Python’s regular expression library  more powerful

String split( ) Simple to use Good when there is a certain pattern of characters you want as a delimiter s = “moo--goo---gai--pan“ s.split(“-”) [‘moo’,’’,’goo’,’’,’’,’gai’,’’,’pan’] s.split(“--“) [‘moo’,’goo’,’-gai’,’pan’] s.split(“---”) [‘moo--goo‘,’gai--pan’]

Using re More often, we want to handle multiple possible delimiters. –Like Java’s StringTokenizer or C’s strtok( ) –Extracting words by ignoring any and all punctuation See handout: tokenize.py –tok = re.compile( )  takes your set of delimiters and creates a “regular expression object” i.e. tokenizer Don’t forget the brackets around delimiters. –tok.split(my_string)  gives list of tokens

Random #s Python has a built-in library (module) called random At top of program, say: import random Two most important functions –random.uniform(a, b) returns a random real number between a and b inclusive –random.randint(a, b) does the same for int