Reading and Writing Files on Your Computer
|
|
- Ralph Fisher
- 6 years ago
- Views:
Transcription
1 Reading and Writing Files on Your Computer
2 Code Snippets HW2-3, HW2-4
3 Function Recap #!/usr/bin/env python3 Though it s called sentence in main, in replace_hello() that value is called text def replace_hello(text): pirate_text = text.replace( hello, ahoy ) return pirate_text def main(): sentence = input( Yarr, type yer words ) sentence_lower = sentence.lower() translated_text = replace_hello(sentence_lower) print(translated_text) if name == main : main() The return of the function is assigned to a variable translated_text
4 Function Recap #!/usr/bin/env python3 Any indented code after a return will not be executed def replace_hello(text): pirate_text = text.replace( hello, ahoy ) return pirate_text def main(): sentence = input( Yarr, type yer words ) sentence_lower = sentence.lower() translated_text = replace_hello(sentence_lower) print(translated_text) if name == main : main() These two lines of code need to be at the bottom of your program
5 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) if name == " main ": main() def out_of_reach(a,b): return a * b $ python3 test.py Traceback (most recent call last): File "test.py", line 10, in <module> main() File "test.py", line 7, in main print(out_of_reach(2,4)) NameError: name 'out_of_reach' is not defined
6 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) if name == " main ": main() def out_of_reach(a,b): return a * b
7 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b When a def is encountered, instead of executing the lines of code, it will compile the code and save it for later def main(): print(out_of_reach(2,4)) if name == " main ": main() def out_of_reach(a,b): return a * b
8 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) Compile main() and save for later if name == " main ": main() def out_of_reach(a,b): return a * b
9 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) if name == " main ": When you run your program, it will execute these two lines after all lines above have been evaluated main() def out_of_reach(a,b): return a * b
10 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) Python will now find the compiled main() function it saved previously if name == " main ": main() def out_of_reach(a,b): return a * b
11 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): Python will look for the function out_of_reach(), but it actually hasn t encountered it yet print(out_of_reach(2,4)) if name == " main ": main() def out_of_reach(a,b): return a * b $ python3 test.py Traceback (most recent call last): File "test.py", line 10, in <module> main() File "test.py", line 7, in main print(out_of_reach(2,4)) NameError: name 'out_of_reach' is not defined
12 Function Recap #!/usr/bin/env python3 def in_reach(a,b): return a + b def main(): print(out_of_reach(2,4)) PUT THESE TWO LINES AT THE if name == " main ": main() BOTTOM OF YOUR FILE TO AVOID THIS PROBLEM def out_of_reach(a,b): return a * b
13 Why we use functions Functions allow you to re-use code that you may use many times Functions help modularize your code, so you can reason about a smaller part of your code at any one time Putting all your code into functions helps reduce bugs in your program Variable names used in one function won t conflict with variables named the same thing in another function You can test each function individually to check if it works correctly Critically analyzing a concrete block of code in a function is easier than a long block of code
14 Modules Libraries provide functionality written by others for use within our own program To make use of these libraries, we import their functionality which are built in modules Python has a LOT of core modules, you can see a list of them at Installing Anaconda initially, gave us even more modules we can use
15 Importing a module We have already used random, and we briefly looked at math and docs.python.org/3/library/math.html #! /usr/bin/env python3 import random def get_computers_choice(): computers_choice = random.choice([ rock, paper, scissors ]) return computers_choice
16 sys module The sys module provides access to interactions with the python interpreter, including information about how the program was started #! /usr/bin/env python3 import sys def main(): filename = input( What file would you like to analyze? ) if.txt not in filename: print(filename + is invalid ) sys.exit() # Program quits execution # Other program code
17 Command-line arguments and sys.argv The words that are typed after your Python program s name in the terminal are called command-line arguments They are available at sys.argv This provides a new modality of input for your programs, input specified at the time the program is run
18 sys.argv Command Argument
19 sys.argv Command Argument
20 sys.argv Command Argument
21 sys.argv sys.argv is a collection of items called a list #!/usr/bin/env python3 import sys print(sys.argv) $ python3 program.py argument1 argument2 argument3 [ program.py, argument1, argument2, argument3 ]
22 sys.argv Get each individual argument using list indexing #!/usr/bin/env python3 import sys print(sys.argv) $ python3 program.py argument1 argument2 argument3 [ program.py, argument1, argument2, argument3 ] sys.argv[0] sys.argv[1] sys.argv[2] sys.argv[3]
23 sys.argv #!/usr/bin/env python3 import sys def main(): kung_fu_panda.txt filename = sys.argv[1] if name == main : main() $ python program.py kung_fu_panda.txt
24 os Provides system-independent operating system functionality Remember a path directs the system where to find a file It is a combination of the directories that contain the file and the filename itself os.path provides useful functionality for paths
25 os.path.exists(path_name) This function will return a boolean that is True if it exists on your computer, otherwise it will return False #!/usr/bin/env python3 import sys def main(): filename = sys.argv[1] if not os.path.exists(filename): print( The file + filename + does not exist ) sys.exit() if name == main : main()
26 Reading and Writing files
27 Computer storage VS Large, slow, permanent Small, fast, temporary
28 The input() function is fairly impractical #!/usr/bin/env python3 import sys def main(): script_text = input( Type in the Kung Fu Panda script, in it s entirety ) if name == main : main()
29 Hard drive storage vs memory With our programs up to today, we have been storing data to variables, this occurs in our computer s temporary memory The computer does not remember this information after your program is run Your computer can also permanently store information on its hard drive Saving your program s file is an example of permanently writing your file to the hard drive Reading and writing files from/to the hard drive represents another input/ output method for our programs
30 Opening/Closing file For both reading and writing, you need to first open a file for reading/writing After you are done reading/writing your program needs to close it When writing to a file, if you don t close your file, the changes you made might not be saved After closing the file, you can t read or write from it again without opening it again
31 Opening/Closing file Opens the file for reading File reference with open(filename, r ) as input_file: text = input_file.read() Don t forget the colon!
32 The file vs filename The filename is just a string that represents the path to the file from the location you ran your program from The file reference connects the program to the file and its contents on the computer filename is a string with open(filename, r ) as input_file: text = input_file.read() input_file refers to the actual file on the computer
33 Reading from a file Use the read() method to read all the text from a file as a complete string with open(filename, r ) as input_file: text = input_file.read() print( The text of the file is + text) After you are done with reading, unindent your code After unindenting, file is automatically closed. The file reference is no longer accessible
34 Writing to a file Use the write() method to write all the text to a file with open(filename, w ) as output_file: print( Writing to + filename) output_file.write(finished_text) # rest of program continues on After you are done with reading, unindent your code After unindenting, file is automatically closed. The file reference is no longer accessible
35 Reading/Writing to file demo
36 Your Homework Complete your program which counts the number of words and sentences in a text Instead of using the input() function, it will load files from the computer For the purpose of this assignment, periods, question marks, exclamation points and ellipses with four dots denote sentence separators Ellipses ( ) don t divide sentences, unless there are four dots (.) Your program will output an answer, but for a long document like the Kung Fu Panda script how do you verify that the answer is correct?
37 Writing test cases for your program You will be asked to write multiple test cases for your program to verify it s functionality These test cases will give you confidence the answer produced by your program is correct
38 Objectives for writing test cases Write test cases that you can manually inspect the correct answer Write the easiest test case you can think of, always run that first Write subsequently more difficult test cases and test those in succession
39 Determining Corner Cases Corner cases are specific test cases that are more likely to fail for incorrectly written programs They generally represent uncommon, but still plausible use cases In your rock, paper, scissors program rock scissors is an example of a corner case, depending on how it s written some programs may interpret this as a rock or a scissors Choose corner cases that you think will likely cause your program to fail, then correct your code until they run correctly
40 Things to test for Non-existent files -> program should produce an error Empty files -> counts should be 0 Files without any punctuation -> Sentence count should be 1 Files with multiple types of punctuation.how many sentences should this be? We don t require your program to correctly consider periods that are part of titles (Dr., Mr., Ms.) or abbreviations (extra credit opportunity!)
41 str.split(separator) An input string is split into smaller strings at each separator The separator can be any string >>> sentence = This is a full sentence. >>> words = sentence.split() >>> print(words) ['This', 'is', 'a', 'full', 'sentence.'] >>> sentence = >>> numbers = sentence.split( - ) >>> print(numbers) [ 456, 186, 413, 389 ]
42 str.split(separator) split returns a list of strings and you can get the number of items by calling length on the result You can get the number of items in the list by using the len() function >>> sentence = This is a full sentence. >>> words = sentence.split() >>> num_words = len(words) >>> print(num_words) 5 >>> sentence = >>> numbers = sentence.split( - ) >>> num_numbers = len(numbers) >>> print(num_numbers) 4
43 Homework hint We haven t talked about lists yet (next class) We don t expect you to do any manipulations on the list returned by str.split() to get the correct answer, except using len() A couple of clever uses of str.replace() to preprocess your text will allow you to only call str.split() once to count sentences, similarly for counting words
Introduction to Computation for the Humanities and Social Sciences. CS 3 Chris Tanner
Introduction to Computation for the Humanities and Social Sciences CS 3 Chris Tanner Lecture 5 But I ve got a blank space [in my text String] baby Taylor Swift Lecture 5 Reading Input From Users Reading
More informationIntroduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
More informationHello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications
Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this
More informationIntroduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python
More informationModularization. Functions and Modules. Functions. Functions how to define
Modularization Functions and Modules MBV-INFx410 Fall 2015 Programs can get big Risk of doing the same thing many times Functions and modules encourage - re-usability - readability - helps with maintenance
More informationDEBUGGING TIPS. 1 Introduction COMPUTER SCIENCE 61A
DEBUGGING TIPS COMPUTER SCIENCE 61A 1 Introduction Every time a function is called, Python creates what is called a stack frame for that specific function to hold local variables and other information.
More informationCME 193: Introduction to Scientific Python Lecture 1: Introduction
CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements
More informationGetting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners
Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationModules and Programs 1 / 14
Modules and Programs 1 / 14 Python Programs Python code organized in modules, packages, and scripts. We ve already used some modules, now we ll learn what they are, how they re orgainized in packages,
More informationLab 5: File I/O CSE/IT 107. NMT Computer Science
CSE/IT 107 NMT Computer Science The danger that computers will become like humans is not as big as the danger that humans will become like computers. ( Die Gefahr, dass der Computer so wird wie der Mensch
More informationCMSC 201 Fall 2016 Lab 09 Advanced Debugging
CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working
More informationCOM110: Lab 2 Numeric expressions, strings, and some file processing (chapters 3 and 5)
COM110: Lab 2 Numeric expressions, strings, and some file processing (chapters 3 and 5) 1) Practice submitting programming assignment 1. Take a few arbitrary modules (.py files) that you have written and
More informationLecture 3: Functions & Modules
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 3: Functions & Modules (Sections 3.1-3.3) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,
More informationfor loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
for loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Reminders use if - elif - else statements for conditional code blocks code blocks share the same indentation
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):
More informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationLecture 3. Functions & Modules
Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should
More informationPart III Appendices 165
Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.
More informationCS Programming Languages: Python
CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer
More informationUnit E Step-by-Step: Programming with Python
Unit E Step-by-Step: Programming with Python Computer Concepts 2016 ENHANCED EDITION 1 Unit Contents Section A: Hello World! Python Style Section B: The Wacky Word Game Section C: Build Your Own Calculator
More informationCS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:
CS 1110, LAB 3: MODULES AND TESTING http://www.cs.cornell.edu/courses/cs11102013fa/labs/lab03.pdf First Name: Last Name: NetID: The purpose of this lab is to help you better understand functions, and to
More informationTable of Contents EVALUATION COPY
Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...
More informationfor loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
for loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Reminders use if - elif - else statements for conditional code blocks memorize the logical operators (==,!=,
More informationPupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1
Pupil Name Year Teacher Target Level Spelling Test No 1 Spelling Test No 2 Spelling Test No 3 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) 1) 2) 3) 4) 5) Spelling Test No 4 Spelling Test No 5 Spelling Test No 6 1) 2)
More informationCS1 Lecture 9 Feb. 5, 2018
CS1 Lecture 9 Feb. 5, 2018 HW 3 available today 5pm, due 9am Monday. Discussion sections this week: loop and string practice HW1 grading done scores posted by noon toeay Common errors: 1) hotel nights,
More informationStarting. Read: Chapter 1, Appendix B from textbook.
Read: Chapter 1, Appendix B from textbook. Starting There are two ways to run your Python program using the interpreter 1 : from the command line or by using IDLE (which also comes with a text editor;
More informationPython Tutorial. Day 2
Python Tutorial Day 2 1 Control: Whitespace in perl and C, blocking is controlled by curly-braces in shell, by matching block delimiters, if...then...fi in Python, blocking is controlled by indentation
More informationCS 100: Computability, Python Lists
CS 100: Computability, Python Lists Chris Kauffman Week 6 Logistics Homework 4 A few Python list exercises Due next Thursday Reading Pattern Ch 5: Algorithms And Heuristics Think Ch 11: Lists (link) Mini-Exam
More informationLecture 3. Functions & Modules
Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 08 Lists Constants Last Class We Covered More on while loops Sentinel loops Priming Reads Boolean flags 2 Any Questions from Last Time? 3 Today s Objectives
More informationAssignment 6 Gale Shapley Python implementation Submit zip file to Canvas by 11:59 Saturday, September 23.
Assignment 6 Gale Shapley Python implementation Submit zip file to Canvas by 11:59 Saturday, September 23. Goals Understand the Gale Shapley algorithm deeply Apply your knowledge about the target complexity
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationLECTURE 4 Python Basics Part 3
LECTURE 4 Python Basics Part 3 INPUT We ve already seen two useful functions for grabbing input from a user: raw_input() Asks the user for a string of input, and returns the string. If you provide an argument,
More informationFile input and output if-then-else. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
File input and output if-then-else Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Opening files The open() command returns a file object: = open(,
More informationCS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:
CS112 Spring 2012 Dr. Kinga Dobolyi Exam 2 Do not open this exam until you are told. Read these instructions: 1. This is a closed book exam. No calculators, notes, or other aids are allowed. If you have
More informationDue: 9 February 2017 at 1159pm (2359, Pacific Standard Time)
CSE 11 Winter 2017 Program Assignment #2 (100 points) START EARLY! Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) PROGRAM #2: DoubleArray11 READ THE ENTIRE ASSIGNMENT BEFORE STARTING In lecture,
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 08 Lists Constants Last Class We Covered More on while loops Sentinel loops Boolean flags 2 Any Questions from Last Time? 3 Today s Objectives To learn about
More informationFile Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming
File Operations Files are persistent data storage titanicdata.txt in PS06 Persistent vs. volatile memory. The bit as the unit of information. Persistent = data that is not dependent on a program (exists
More informationCS1 Lecture 5 Jan. 25, 2019
CS1 Lecture 5 Jan. 25, 2019 HW1 due Monday, 9:00am. Notes: Do not write all the code at once before starting to test. Take tiny steps. Write a few lines test... add a line or two test... add another line
More informationFILE HANDLING AND EXCEPTIONS
FILE HANDLING AND EXCEPTIONS INPUT We ve already seen how to use the input function for grabbing input from a user: input() >>> print(input('what is your name? ')) What is your name? Spongebob Spongebob
More informationCSE 143: Computer Programming II Summer 2017 HW4: Grammar (due Tuesday, July :30pm)
CSE 143: Computer Programming II Summer 2017 HW4: Grammar (due Tuesday, July 25 2017 11:30pm) This assignment focuses on recursive programming, regular expressions, and grammars. It will also give you
More informationLaboratory Exercise #0
Laboratory Exercise #0 This assignment focuses on the mechanics of installing and using Python. The deadline for Mimir submission is 11:59 PM on Monday, January 8. 1. Complete the steps given below to
More informationENGR 102 Engineering Lab I - Computation
ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;
More informationIntroduction to: Computers & Programming: Review prior to 1 st Midterm
Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in
More informationFile Operations. Working with files in Python. Files are persistent data storage. File Extensions. CS111 Computer Programming
File Operations Files are persistent data storage titanicdata.txt in PS07 Persistent vs. volatile memory. The bit as the unit of information. Persistent = data that is not dependent on a running program
More informationA Little Python Part 1. Introducing Programming with Python
A Little Python Part 1 Introducing Programming with Python Preface Not a complete course in a programming language Many details can t be covered Need to learn as you go My programming style is not considered
More informationIntroduction to Programming with JES
Introduction to Programming with JES Titus Winters & Josef Spjut October 6, 2005 1 Introduction First off, welcome to UCR, and congratulations on becoming a Computer Engineering major. Excellent choice.
More informationAPT Session 2: Python
APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/
More informationIntroduction to Python
Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243 Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14
More informationIntroduction to Linux Part 2b: basic scripting. Brett Milash and Wim Cardoen CHPC User Services 18 January, 2018
Introduction to Linux Part 2b: basic scripting Brett Milash and Wim Cardoen CHPC User Services 18 January, 2018 Overview Scripting in Linux What is a script? Why scripting? Scripting languages + syntax
More informationCS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures
CS177 Recitation Functions, Booleans, Decision Structures, and Loop Structures Functions Collection of instructions that perform a task as: o Printing your name and course. o Calculating the average of
More informationPython 1: Intro! Max Dougherty Andrew Schmitt
Python 1: Intro! Max Dougherty Andrew Schmitt Computational Thinking Two factors of programming: The conceptual solution to a problem. Solution syntax in a programming language BJC tries to isolate and
More informationScripting With Jython
Scripting With Jython In this chapter, we will look at scripting with Jython. For our purposes, we will define scripting as the writing of small programs to help out with daily tasks. These tasks are things
More informationBasic Syntax - First Program 1
Python Basic Syntax Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello, Python!";#hello world program run this program
More informationChris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9
http://xkcd.com/353/ Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9 Python Python is a general-purpose programming language, meaning you can write any kind
More informationFile input and output and conditionals. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
File input and output and conditionals Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Opening files The built-in open() function returns a file object:
More informationCS 220: Introduction to Parallel Computing. Arrays. Lecture 4
CS 220: Introduction to Parallel Computing Arrays Lecture 4 Note: Windows I updated the VM image on the website It now includes: Sublime text Gitkraken (a nice git GUI) And the git command line tools 1/30/18
More informationIntroductory Linux Course. Python II. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University
Introductory Linux Course Python II Martin Dahlö UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2018 Outline Short recap Functions Similarity of sequences
More informationCSCI 141 Computer Programming I. Filip Jagodzinski
Filip Jagodzinski Announcement Using online resources for help I want you to learn from others I want you to learn how to use (good) online resources Learning on your own is a good thing Announcement Using
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday
More informationAdvanced topics, part 2
CS 1 Introduction to Computer Programming Lecture 24: December 5, 2012 Advanced topics, part 2 Last time Advanced topics, lecture 1 recursion first-class functions lambda expressions higher-order functions
More informationCS150 Sample Final Solution
CS150 Sample Final Solution Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1)
More informationIntroduction to Python
Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level
More informationfor loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
for loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Must be indented for loop Allows you to perform an operation on each element in a list (or character in
More informationCS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017
CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 Previous class We have learned the path and file system.
More informationCS150 Sample Final. Name: Section: A / B
CS150 Sample Final Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1) the final
More informationCS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points
CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points Files to submit: 1. HW3.py This is a PAIR PROGRAMMING Assignment: Work with your partner! For pair
More information: Intro Programming for Scientists and Engineers Final Exam
Final Exam Page 1 of 6 600.112: Intro Programming for Scientists and Engineers Final Exam Peter H. Fröhlich phf@cs.jhu.edu December 20, 2012 Time: 40 Minutes Start here: Please fill in the following important
More informationScientific Python. 1 of 10 23/11/ :00
Scientific Python Neelofer Banglawala Kevin Stratford nbanglaw@epcc.ed.ac.uk kevin@epcc.ed.ac.uk Original course authors: Andy Turner Arno Proeme 1 of 10 23/11/2015 00:00 www.archer.ac.uk support@archer.ac.uk
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS TESTING, MAIN, GLOBAL VARIABLES João Correia Lopes INESC TEC, FEUP 23 October 2018 FPRO/MIEIC/2018-19 23/10/2018 1 / 24 INTRODUCTION GOALS By the end of this class, the student
More informationIntroduction to: Computers & Programming Defining Identifiers: Objects with Names
Introduction to: Computers & Programming Defining Identifiers: Objects with Names Adam Meyers New York University Outline The types of objects with names Functions, Variables, Programs, Modules, etc. Defining
More informationPython at Glance. a really fast (but complete) ride into the Python hole. Paolo Bellagente - ES3 - DII - UniBS
Python at Glance a really fast (but complete) ride into the Python hole. Paolo Bellagente - ES3 - DII - UniBS Python 2.7 isn t compatible with python 3!!!! Rule #1: RTFM Read The F*****g Funny Manual Rule
More informationCS 220: Introduction to Parallel Computing. Beginning C. Lecture 2
CS 220: Introduction to Parallel Computing Beginning C Lecture 2 Today s Schedule More C Background Differences: C vs Java/Python The C Compiler HW0 8/25/17 CS 220: Parallel Computing 2 Today s Schedule
More information1007 Imperative Programming Part II
Agenda 1007 Imperative Programming Part II We ve seen the basic ideas of sequence, iteration and selection. Now let s look at what else we need to start writing useful programs. Details now start to be
More informationIntroduction to Python
Introduction to Python NaLette Brodnax The Institute for Quantitative Social Science Harvard University January 24, 2018 what we ll cover first 0 Python installation one-minute poll 1 introduction what
More informationExceptions CS GMU
Exceptions CS 112 @ GMU Exceptions When an unrecoverable action takes place, normal control flow is abandoned: an exception value crashes outwards until caught. various types of exception values can be
More informationCh.2: Loops and lists
Ch.2: Loops and lists Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Simula Research Laboratory 1 University of Oslo, Dept. of Informatics 2 Aug 29, 2018 Plan for 28 August Short quiz on topics from last
More informationPYTHON. Varun Jain & Senior Software Engineer. Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT. CenturyLink Technologies India PVT LTD
PYTHON Varun Jain & Senior Software Engineer Pratap, Mysore Narasimha Raju & TEST AUTOMATION ARCHITECT CenturyLink Technologies India PVT LTD 1 About Python Python is a general-purpose interpreted, interactive,
More informationPython is available at: https://www.python.org/ Why Python is awesome: https://www.python.org/about/success/
The Python IDLE: Introduction This tutorial assumes you have a PYTHON 3 version of the programming language installed. (Current version at of this writing is Python 3.6) Python is available at: https://www.python.org/
More informationa b c d a b c d e 5 e 7
COMPSCI 230 Homework 9 Due on April 5, 2016 Work on this assignment either alone or in pairs. You may work with different partners on different assignments, but you can only have up to one partner for
More informationCS1 Lecture 5 Jan. 26, 2018
CS1 Lecture 5 Jan. 26, 2018 HW1 due Monday, 9:00am. Notes: Do not write all the code at once (for Q1 and 2) before starting to test. Take tiny steps. Write a few lines test... add a line or two test...
More informationPython Programming, bridging course 2011
Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/
More informationWhat is the minimum number of letters that could have been changed?
Homework 4, CSE 232 Due September 24 Note: On most of the problem sets through the semester, I ll put a horizontal line with Optional under it. Any problems below this section are encouraged - I think
More informationCMSC 201 Spring 2016 Homework 7 Strings and File I/O
CMSC 201 Spring 2016 Homework 7 Strings and File I/O Assignment: Homework 7 Strings and File I/O Due Date: Monday, April 4th, 2016 by 8:59:59 PM Value: 40 points Homework 7 is designed to help you practice
More informationKey Differences Between Python and Java
Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.
More informationWriting and Running Programs
Introduction to Python Writing and Running Programs Working with Lab Files These instructions take you through the steps of writing and running your first program, as well as using the lab files in our
More informationLab 4: Bash Scripting
Lab 4: Bash Scripting February 20, 2018 Introduction This lab will give you some experience writing bash scripts. You will need to sign in to https://git-classes. mst.edu and git clone the repository for
More informationIntroduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15
1 LECTURE 1: INTRO Introduction to Scientific Python, CME 193 Jan. 9, 2014 web.stanford.edu/~ermartin/teaching/cme193-winter15 Eileen Martin Some slides are from Sven Schmit s Fall 14 slides 2 Course Details
More informationCMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)
CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings) Assignment: Homework 4 Lists (and Loops and Strings) Due Date: Friday, March 3rd, 2017 by 8:59:59 PM Value: 40 points Collaboration: For Homework
More informationwhile loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas
while loops Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Hints on variable names Pick names that are descriptive Change a name if you decide there s a better
More informationPython for Analytics. Python Fundamentals RSI Chapters 1 and 2
Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,
More informationPython File Modes. Mode Description. Open a file for reading. (default)
UNIT V FILES, MODULES, PACKAGES Files and exception: text files, reading and writing files, format operator; command line arguments, errors and exceptions, handling exceptions, modules, packages; Illustrative
More informationAssignment 7: functions and closure conversion
Assignment 7: functions and closure conversion ECEN 4553 & 5013, CSCI 4555 & 5525 Prof. Jeremy G. Siek October 20, 2007 The main ideas for this week are: first-class functions lexical scoping of variables
More informationSpring Semester 10 Exam #1 Dr. Dillon. (02/18)
Spring Semester 10 Exam #1 Dr. Dillon. (02/18) Form 1 B Last name (printed): First name (printed): Directions: a) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b) You have 80 minutes
More informationCIT 590 Homework 5 HTML Resumes
CIT 590 Homework 5 HTML Resumes Purposes of this assignment Reading from and writing to files Scraping information from a text file Basic HTML usage General problem specification A website is made up of
More informationIntroductory Linux Course. Python II. Pavlin Mitev UPPMAX. Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University
Introductory Linux Course Python II Pavlin Mitev UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2017 Outline Short recap Functions Similarity of sequences
More informationUnit Testing In Python
Lab 13 Unit Testing In Python Lab Objective: One of the hardest parts of computer programming is ensuring that a program does what you expect it to do. For instance, a program may fail to meet specifications,
More informationProgramming Fundamentals and Python
Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains
More information