CIT 590 Intro to Programming Lecture 6. Vote in the doodle poll so we can use some fancy algorithm to pair you up You.

Slides:



Advertisements
Similar presentations
Input and Output Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advertisements

Lectures 10 & 11.
Python Basics: Statements Expressions Loops Strings Functions.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
COMP234 Perl Printing Special Quotes File Handling.
Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Chapter 8 Overview – Learn to use try catch blocks – Learn to use streams – Learn to use text files.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
Files in Python The Basics. Why use Files? Very small amounts of data – just hardcode them into the program A few pieces of data – ask the user to input.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
Week 14 - Monday.  What did we talk about last time?  Image manipulation  Inheritance.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Selecting and Combining Tools F. Duveau 02/03/12 F. Duveau 02/03/12 Chapter 14.
Input/Output Chapters 7 & 9. Output n Print produces output > (print 100) n It also returns the value it printed –that’s where the second 100 came.
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Sed sed is a program used for editing data. It stands for stream editor. Unlike ed, sed cannot be used interactively. However, its commands are similar.
CS 470 Lab 5 Comment your code. Description of Lab5 Create Four projects – Driver – Producer – Filter – Consumer.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Guide to Programming with Python Chapter Seven (Part 1) Files and Exceptions: The Trivia Challenge Game.
File I/O 11_file_processing.ppt
Documentation and Comments. What’s a comment? A comment is a simple form of documentation. Documentation is text that you the programmer write to explain.
Course A201: Introduction to Programming 12/9/2010.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
Chapter 9-Text File I/O. Overview n Text File I/O and Streams n Writing to a file. n Reading from a file. n Parsing and tokenizing. n Random Access n.
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.
Dictionaries.   Review on for loops – nested for loops  Dictionaries (p.79 Learning Python)  Sys Module for system arguments  Reverse complementing.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Files & Directories.
Using Text Files in Excel File I/O Methods. Working With Text Files A file can be accessed in any of three ways: –Sequential access: By far the most common.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
16. Python Files I/O Printing to the Screen: The simplest way to produce output is using the print statement where you can pass zero or more expressions,
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.
GEO375 Final Project: From Txt to Geocoded Data. Goal My Final project is to automate the process of separating, geocoding and processing 911 data for.
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Lecture 4 Python Basics Part 3.
Chapter 16 Web Pages And CGI Scripts Department of Biomedical Informatics University of Pittsburgh School of Medicine
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
CIT 590 Intro to Programming Files etc. Agenda Files Try catch except A module to read html off a remote website (only works sometimes)
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.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
IIITD File Input / Output In Python. File and operations  File is a named location on disk to store related information  When we want to read from or.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
FILE I/O: Low-level 1. The Big Picture 2 Low-Level, cont. Some files are mixed format that are not readable by high- level functions such as xlsread()
Input from STDIN STDIN, standard input, comes from the keyboard.
Getting Started with R.
(optional - but then again, all of these are optional)‏
MATLAB: Structures and File I/O
Cookies BIS1523 – Lecture 23.
Files I/O, Streams, I/O Redirection, Reading with fscanf
File Handling Programming Guides.
Topics Introduction to File Input and Output
Using files Taken from notes by Dr. Neil Moore
Building Web Applications
Learning to Program in Python
In Class Programming BIS1523 – Lecture 11.
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
Data Structures – 1D Lists
Video list editor BIS1523 – Lecture 24.
Notes about Homework #4 Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming:
CMSC201 Computer Science I for Majors Final Exam Information
Topics Introduction to File Input and Output
Winter 2019 CISC101 4/29/2019 CISC101 Reminders
Topics Introduction to File Input and Output
How to read from a file read, readline, reader
Introduction to Computer Science
Presentation transcript:

CIT 590 Intro to Programming Lecture 6

Vote in the doodle poll so we can use some fancy algorithm to pair you up You have to program in pairs I sadly still don’t know if we have an odd number of students or an even number. We don’t know the algorithm yet but it has to satisfy the obvious time constraint

Agenda Files Try catch except A module to read html off a remote website

Basic file operations f = open(‘myRandomFile.txt’) Open(“”) Default is the read only mode Open(“”, “w”) Open the file in the mode that you would like to use it Read - r Write - w Append – a Opening a file in the ‘r+’ mode if you want to read and write to it at the same time. Use this one with caution

Reading and writing to a file Read, readline, readlines Using a while loop to read every single line of a file Write, writelines Close() – why should I close a file Cleaning up The operating system should close the file, but that behavior is not entirely under your control Remember that opening a file for writing will remove the old values fileExperiments.py

Tell and seek Once I have read a file all the way through how do I go back to the start?? Or in general, how do I mark a point in the file that I now want to come back to. x = f.tell() #do some reading writing etc etc on f f.seek(x) to get back to where we were

What file formats are supported? Text files work best in that they do not come with headers and footers etc You can always read in binary Usually if you are dealing with a specific format, you will be using some extra packages

Looping through the contents of a file Instead of using a while loop with a readline, python provides the ability to do a for loop For line in f will read one single line of the file and assign it to the temp variable line. Loop until EOF (end of file)

The os module File management is generally being done at the operating system level In Python if you want to use command prompt like commands ‘import os’ os.listdir(‘C:\Python27’) os.rename(‘oldfilename’, ‘newfilename’)

Exceptions! Try except try: Something except error, e: do something with the error. Maybe print some message else: #it was a successful attempt. Now do the real work tryExceptForFiles.py

Standard input and output The sys module gives you access to some built in ‘files’ The console input is basically just sys.stdin Similarly the console output is sys.stdout Sys module has other built in functions like sys.argv to get the command line arguments. add10ToConsoleInput.py

The file sort example from the book Good example for top down design fileSort.py

Reading from a url Import urllib Urllib.urlopen( Only works on a subset of sites. Secure sites will usually not allow you to grab info that easily. My seas website isn’t particularly secure …. getAllTAs.py