Lilian Blot TPOP Practical Assignment Optional, but you are strongly encourage to do it, especially if you are new to programming Available on Module webpage.

Slides:



Advertisements
Similar presentations
Lilian Blot PART III: ITERATIONS Core Elements Autumn 2012 TPOP 1.
Advertisements

MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
Lilian Blot CORE ELEMENTS SELECTION & FUNCTIONS Lecture 3 Autumn 2014 TPOP 1.
Sections of Ch. 12, 13, 14 Prof. V. Norman PhD, MS, BS, DDS, Esq.
Lilian Blot CORE ELEMENTS PART V: FUNCTIONS PARAMETERS & VARIABLES SCOPE Lecture 5 Autumn 2014 TPOP 1.
Initial set-up and use of OAS for Administrators/Coordinators.
Alternative FILE formats
Basics Of Spreadsheets Chapter Spreadsheet spreadsheet: grid of cells, each of which can contain text data or numeric data.
Lilian Blot TOWARDS MORE ADVANCED CONCEPTS & OBJECT ORIENTED PROGRAMMING Building Data Structure Autumn 2014 TPOP 1.
Lilian Blot TPOP Practical Assignment Optional, but you are strongly encourage to do it, especially if you are new to programming Available on Module.
Chapter 7 Data Management. Agenda Database concept Import data Input and edit data Sort data Function Filter data Create range name Calculate subtotal.
2015/6/301 TransCAD Managing Data Tables. 2015/6/302 Create a New Table.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Lecture 23 – Python dictionaries 1 COMPSCI 101 Principles of Programming.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Lists in Python.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
Miscellaneous Excel Combining Excel and Access. – Importing, exporting and linking Parsing and manipulating data. 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Guide to Programming with Python Chapter Seven (Part 1) Files and Exceptions: The Trivia Challenge Game.
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
CS190/295 Programming in Python for Life Sciences: Lecture 3 Instructor: Xiaohui Xie University of California, Irvine.
Complete theory from last lesson… Put today’s date in the front of your book Read pages 46 and 47 of the textbook…
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
CIT 590 Intro to Programming Files etc. Announcements From HW5 onwards (HW5, HW6,…) You can work alone. You can pick your own partner. You can also stick.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 18 Using text files to share data with other programs 5/07/09 Python Mini-Course:
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Conversion Functions.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
Files Tutor: You will need ….
Integrate, check and share documents Module 3.3. Integrate, check and share documents Module 3.3.
Week 9 : Text processing (Reading and writing files)
Early File I/O To help you get started with your final project 1. Definition of “high level” 2. Is using a High Level function appropriate? 3. xlsread()
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
CSV Files Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Lakshit Dhanda. Output Formatting Python has ways to convert any value to a string. 2 Methods repr() – meant to generate representations of values read.
Workplace Equity Information Management System (WEIMS) Creating and Importing Files November 18, 2014.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
Today… Files from the Web! Dictionaries. Lists of lists. Winter 2016CISC101 - Prof. McLeod1.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Containers and Lists CIS 40 – Introduction to Programming in Python
CSC 108H: Introduction to Computer Programming
Data File Import / Export
Python I/O.
Lecture 13 Input/Output Files.
Topics Introduction to File Input and Output
In Class Program: Today in History
CISC101 Reminders Slides have changed from those posted last night…
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
Fundamentals of Data Structures
TRAINING OF FOCAL POINTS on the CountrySTAT SYSTEM based on FENIX
I210 review.
Introduction to Programming
Topics Sequences Introduction to Lists List Slicing
Files Handling In today’s lesson we will look at:
Fundamentals of Python: First Programs
Topics Introduction to File Input and Output
Topics Sequences Introduction to Lists List Slicing
Introduction to Programming
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
HTML Forms What are clients? What are servers?
Topics Introduction to File Input and Output
How to read from a file read, readline, reader
Files Chapter 8.
Presentation transcript:

Lilian Blot TPOP Practical Assignment Optional, but you are strongly encourage to do it, especially if you are new to programming Available on Module webpage from next week (week 6) Deadline: Friday 14 November at 12:00 pm.  submitted by to  with the subject: "TPOP Assignment“ Feedback and Mark given by appointment ONLY must improve / pass / good (2.1) / very good (1st) Autumn 2014 TPOP 1

Lilian Blot PERSISTENT DATA USING TEXT FILES Lecture 10 Autumn 2014 TPOP 2

Lilian Blot Review To date we have use variables to store set of data: String for collection of characters (immutable)  ‘this is a sentence’ Tuples for collection of objects (immutable)  (1, ‘another sentence’, 5.3, (3,0), ‘A’) Lists for collection of objects (mutable)  [1, ‘TPOP’, 5.3, (3,0), [1,4,2],‘A’] Dictionaries for collection of mapping keys and values (mutable)  {1: ‘one’, 2:‘two’, ‘French’:{1:’un’, 2:’deux’}, ‘digits’:[‘0’,’1’,’2’,’3’,’4’,’5’,’6’,’7’,’8’,’9’]} Autumn 2014 TPOP 3

Lilian Blot Overview However when the program exits, all data is lost. There is a need for persistent data. Today’s lecture will address:  Opening/closing text files  Reading a text file content  Writing on a text file  Formatting data structure Autumn 2014 TPOP 4

Lilian Blot Writing data to a file Code: save the content of a list into a text file. Autumn 2014 TPOP 5 Method nameuseExplanation openf=open(filename,’r’) Open a file called filename for read only. Return a object. See help(file) in Python shell. openf=open(filename,’w’) Open a file called filename for write only. Return a object. closef.close()Close the file. writef.write(aString) Add the string aString at the end of the file. f must be opened (using open in row 2) and not closed (row 3 not used yet).

Lilian Blot Reading data from a file Code: read the content of a text file and store it into a list. Autumn 2014 TPOP 6 Method nameuseExplanation read f.read() f.read(n) Reads and returns a string of n characters, or the entire file content as a single string if n is not provided readlinef.readline() Reads and returns the next line of the file with all text up to and including the newline character (‘\n’). readlines f.readlines() f.readlines(n) Reads and returns a list of n strings each representing a single line of the file. If n is not provided, then all lines of the file are returned.

Lilian Blot Representing a Table (spreadsheet) How could we represent the following spreadsheet in Python? Autumn 2014 TPOP 7 SurnameFirstnameNationality PaulCairnsUK WillSmithUK LilianBlotIrrevocably French ……… table = [[’paul’,’Cairns’,’UK’], [’will’,’Smith’,’UK’], …] Code 2D list

Lilian Blot Formatting Strings We may want to format the values into a string before writing to a file: Autumn 2014 TPOP 8 CharacterDescription d, iInteger or long integer fFloating point as m.ddddd cSingle character s String or any Python object that can be converted to a string by using the str function. >>> aString = '%s is celebrating is %ith birthday next year‘ %('lilian',29) >>> aString 'lilian is celebrating is 29th birthday next year' >>> Code

Lilian Blot Formatting Strings We may want to format the values into a string before writing to a file: Autumn 2014 TPOP 9 ModifierExampleDescription number%20dPut the value in a field of 20 characters wide. -%-20dSame as above but left-justified +%+20dSame as above but right-justified 0%020d Put the value in a field of 20 characters wide, fill in with leading zeros..%20.2f Put the value in a field of 20 characters wide, with two characters to the right of the decimal point.

Lilian Blot Representing a Table (spreadsheet) Rewriting the table with string formatting Autumn 2014 TPOP 10 SurnameFirstnameNationality PaulCairnsUK WillSmithUK LilianBlotIrrevocably French ……… table = [[’paul’,’Cairns’,’UK’], [’will’,’Smith’,’UK’], …] Code

Lilian Blot Representing a Table (spreadsheet) What about missing data? Autumn 2014 TPOP 11 SurnameFirstnamemiddlenameNationality PaulCairnsUK WillSmithUK LilianBlotJ-LIrrevocably French AlanFrischM ………… table = [[’paul’,’Cairns’,’UK’], [’will’,’Smith’,’UK’], …] Code Is this working?

Lilian Blot Defining a file Format CSV files: each field is separated by a comma. Missing fields: Autumn 2014 TPOP 12 Paul, Cairns, UK Will, Smith, UK Lilian, blot, French File Paul, Cairns,, UK Will, Smith,, UK Lilian, blot, J-L, French Alan, Frisch, M, File

Lilian Blot Defining a file Format Extensible Markup Language (XML) Autumn 2014 TPOP 13 "Aalborg, Denmark ",AAL "Aalesund, Norway ",AES "Aarhus, Denmark - Bus service ",ZID CSV File Aalborg, Denmark AAL Aalesund, Norway AES XML File

Lilian Blot Summary We have seen the need of persistent data Reading/writing text file Defining a file format Formatting string to a specified format Another type of files: Binary Files (not this year) Autumn 2014 TPOP 14

Lilian Blot Exercises Get the file containing the average temperatures in the UK at the following address:  nked/UK.txt nked/UK.txt  As you can see, one line contains many different years  Reformat the file so the rows are years in increasing order, and columns are month from January to December. This is a difficult exercise, so do it once you finished the exercises provided in the practical. Autumn 2014 TPOP 15