Working with data files; the len() and.split() functions
|
|
- Miranda Bennett
- 6 years ago
- Views:
Transcription
1 Basic File Operations Working with data files; the len() and.split() functions Objectives To use text files to store large data sets To access online data sources To introduce the for loop To introduce ASCII, Unicode, and Latin-1 To use the len() function and.split() method 1
2 Text File Sequence of characters, organized into lines, stored on some external memory device (such as a hard drive) End of line markers (newline character) - Sometimes the last line is missing the newline character Not all files are text files - Some contain binary information instead - We aren't concerned with these right now Files, File Names, and File Handles File a set of data, stored on a disk or flash drive of some sort - Sometimes called a disk file - Text strings or binary data File name the data set s name, used to locate the data set on the drive - Just a text string - Often includes an extension, e.g..txt File handle a Python object, used to refer to and operate on a file 2
3 Things to Do with Files Open a file - open() Read from a file - read()» some number of bytes - readline()» read a line of text - readlines()» read all lines of text Print to a file - print() function, with a keyword argument Write to a file -.write() method» writes one string or a block of bytes Printing Your Output to a File First, open the file: - handle = open( mynewfile.txt, w ) Use the handle in print() statements: - print( example output, file=handle ) - Use as many print() statements as desired; use formatting as desired Finish by closing the file: - handle.close() 3
4 Try: fn = input('new file name?') fh = open(fn, 'w') print('my name is Bob', file=fh) # use your name x = 2**13 print('{} equals {:#x}'.format(x,x), file=fh) print( file=fh ) # print a blank line print('goodbye!', file=fh) Open your new file in a text editor to verify that it was created An Alternative to Printing Writing To a File.write() method writes exactly one string - handle.write( 'This is a string' ) No formatting, no newline at the end - Add your own newlines: handle.write( 'This is a string\n' ) Build a formatted string of desired output, then write it out to the file 4
5 .write( ) example Add your own newlines.write() is a method of the file object Why use.write() instead of print()? More efficient than print() function More general, and allows more precise control of what goes into the file Supports writing of binary / non-text data to a file. 5
6 Organization of Text Files Text files contain sequences of ASCII characters - We ll consider Unicode later Text is grouped into lines print() statements each generate one line of output - (usually) A Detail about Lines in Text Files Lines are separated by newline characters (or end-of-line sequences), and different operating systems use different newlines - MSDOS, Windows: ASCII 0x0d,0x0a known as carriage return, line feed - 0x0d == 13, 0x0a == 10 - Linux: ASCII 0x0a only known as newline or linefeed - MacOS: ASCII 0x0d only known as carriage return Blank lines contain a newline by itself Python handles all three formats the same 6
7 So, How to Read Input From a Text File? First, open the file for reading: - handle = open( mydatafile.txt, r ) Next, read one or more lines into variables: - l0 = handle.readline() # read 1 line into variable - l1 = handle.readline() # read next line - l2 = handle.readline() #...and again Close the file when you re done with it: - handle.close() try: fn = input('what filename did you use before?') fh = open(fn, 'r') l0 = fh.readline() print( '{:3d} -->{}<--'.format(len(l0), l0) ) l1 = fh.readline() print( '{:3d} -->{}<--'.format(len(l1), l1) ) l2 = fh.readline() print( '{:3d} -->{}<--'.format(len(l2), l2) ) 7
8 The len() Function len( 'string' ) provides the length of the string Examples: - len('abcde') # equals 5 - s = 'XYZ' len(s) # equals 3 - len( '' ) # equals 0 len() is used for lists and dictionaries too - we'll see this later The for statement for repeats a logical block of actions, once for each element in a collection of things - A file is a collection of lines of text - The 'lines' list is a collection of text strings General structure: for <variable> in <collection> : statement statement statement... 8
9 for examples for l in 'qwertyuiop': print(l) # print 1 char per line s = '' for w in ['These', 'are', 'words', '.']: s += w print(s) # build a sentence from a word list n = 1 for i in range(5,10): # range( ) generates integers n += i**2 print('sum of squares: ', n) for and text files for statement treats the.readlines() method as a collection of all the textlines in the file - or as many as are left, if part of the file has been read already or if a.seek() has moved to a particular position in the file Typical use looks like this: - for l in handle.readlines(): print( len(l), '-->%s<--' % (l) ) # do other things with l... 9
10 Example Open the file for reading again: - handle = open( mydatafile.txt, r ) Read each of the file's lines into a list: - lines = [] # create empty list for l in handle.readlines(): lines.append(l) # get all lines, 1 at a time, # add to end of list Close the file when you re done with it: - handle.close() Try: fn = input('datafile name? ') fh = open(fn, 'r') for l in fh.readlines(): print('{:3d} ->{}<-'.format(len(l), l)) 10
11 back to text files Once a file is opened for reading, its file handle has methods:.readlines()» read all lines of text, one at a time.readline()» read a single line of text.read( n )» read n characters, default is to read the whole file.seek( n )» find a specific location in the file ( useful with.read() ).close()» close the file to prevent changing it by accident Getting Numbers From Text Files As with the input() statement, all received data consists of text strings As needed, convert the text to numbers - Use int() or float() to convert "number-like" strings into numbers Example: - valuestring = handle.readline() value = float(valuestring) Example, reworked: - value = float( handle.readline() ) 11
12 Try: first set up some random data fn = input('data file name?') fh = open(fn, 'w') import random for line in range(17): print(random.random(), file=fh) Creates a number between 0.0 and 1.0 Look at your file in a text editor Try: read the data back fn = input('data file?') fh = open(fn, 'r') x = 0 n = 0 for line in fh.readlines(): x += float(line) n += 1 print( \ Add number into variable X 'Average of {} values is {}'.format(n, x/n)) 12
13 Getting Numbers From Formatted Files What if more than one value on a line? - Use.split() to form a list of substrings - Convert list elements individually with int() or float() as desired» if in doubt, use float() What if line contains additional information? - Use.split() to form a list of substrings - Choose which element of the list you want - Convert that element with int() or float() Try: store some random integers fn = input('data file name?') fh = open(fn, 'w') import random for line in range(17): for i in range(10): print(random.randrange(-5, 5), \ print(file=fh) end=' ', file=fh) Inspect your file in a text editor Creates numbers from -5 through +4 13
14 Try: read the data back fn = input('data file?') fh = open(fn, 'r') x = 0 n = 0 for line in fh.readlines(): values = line.split() print(values) for v in values: x += int(v) n += 1 Add numbers into variable X print('sum of {} values is {}'.format(n, x)) Try: read from a formatted file Copy 'earthquakes0a.txt from your O: drive or browse to 'montcs.bloomu.edu/~bobmon/datasets/earthquakes0a.txt' - Save file to your P-drive handle = open('earthquakes0a.txt', 'r') maxmagnitude = 0 location = None for line in handle.readlines(): parts = line.split() mag = float(parts[5]) if mag > maxmagnitude: maxmagnitude = mag location = parts[6:] print('strongest: {} at {}'.format(maxmagnitude, \ location)) 14
15 ASCII, Unicode, and Python Text Files Text files contain text, but what is text? Many files use 7-bit ASCII - "Lowest common denominator" Some files use 8-bit extended ASCII - "ISO " encoding, a.k.a. "latin-1" Unicode is becoming more common - "UTF-8" encodes characters into 1, 2, or 4 bytes: Ɱ are examples Python 3 tries to open text files using UTF-8 or latin-1, depending on the host system - Windows: latin-1; Linux/Mac: UTF-8 Try: Copy the files country-population.2016.utf-8.txt and country-population.2016.latin-18.txt from your O: drive Do the following (in the IDLE shell): fh = open('country-population.2016.utf-8.txt', 'r') linesa = fh.readlines() fh = open('country-population.2016.latin-1.txt', 'r') linesb = fh.readlines() 15
16 Continued: Compare line 162 from each file: print(linesa[162]) print(linesb[162]) Do the lines look the same? Bytes Bytes are groups of 8 bits - Computer file and memory sizes are measured in bytes 7-bit ASCII characters take 1 byte each 8-bit extended ASCII also uses 1 byte each - Characters such as: «ñ - Latin-1 encoding is NOT compatible with UTF-8! 8-bit ASCII files must be opened with the correct encoding - or no encoding, as a "binary file" this is messier 16
17 Reading 8-bit ASCII Files Statements like "fh = open('file.txt', 'r')" default to UTF-8 Open 8-bit ASCII files as Latin-1 (or ISO ) - fh = open('file.txt','r',encoding='latin-1') Handle as usual from here on Try: fh = open( 'country-population.2016.txt', \ 'r', encoding='latin-1' ) lines = [] for l in fh.readlines(): lines.append(l) print( len(lines), 'entries in file' ) print(lines[56]) 17
18 What if you don't know how the file was encoded? Most general solution: Treat it as bytes Open the file in binary mode: - fh = open('unknownfile.txt', 'rb') Read byte strings: - bs = fh.readline() Try to decode the line using possible encodings: - try: data = bs.decode('utf-8') except: data = bs.decode('latin-1') try-except: another topic we'll explore later 18
CPSC 217 Midterm (Python 3 version)
CPSC 217 Midterm (Python 3 version) Duration: 50 minutes 6 March 2009 This exam has 61 questions and 11 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance
More informationTeaching London Computing
Teaching London Computing Programming for GCSE Topic 10.1: Files William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London Aims Be able to develop simple programs
More informationConverting File Input
Converting File Input As with the input func.on, the readline() method can only return strings If the file contains numerical data, the strings must be converted to the numerical value using the int()
More informationSequences: Strings, Lists, and Files
Sequences: Strings, Lists, and Files Read: Chapter 5, Sections 11.1-11.3 from Chapter 11 in the textbook Strings: So far we have examined in depth two numerical types of data: integers (int) and floating
More informationTextbook. Topic 8: Files and Exceptions. Files. Types of Files
Textbook Topic 8: Files and A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools. -Douglas Adams 1 Strongly Recommended
More informationTopics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming
Topics C H A P T E R 1 Introduction to Computers and Programming Introduction Hardware and Software How Computers Store Data Using Python Introduction Computers can be programmed Designed to do any job
More informationExercise: The basics - variables and types
Exercise: The basics - variables and types Aim: Introduce python variables and types. Issues covered: Using the python interactive shell In the python interactive shell you don t need print Creating variables
More informationCHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS
These are sample pages from Kari Laitinen s book "A Natural Introduction to Computer Programming with Java". For more information, please visit http://www.naturalprogramming.com/javabook.html CHAPTER 5
More informationUnicode Support. Chapter 2:
Unicode Support Chapter 2: SYS-ED/Computer Education Techniques, Inc. Ch 2: 1 SYS-ED/Computer Education Techniques, Inc. Ch 2: 1 Objectives You will learn: Unicode features. How to use literals and data
More informationFiles on disk are organized hierarchically in directories (folders). We will first review some basics about working with them.
1 z 9 Files Petr Pošík Department of Cybernetics, FEE CTU in Prague EECS, BE5B33PRG: Programming Essentials, 2015 Requirements: Loops Intro Information on a computer is stored in named chunks of data called
More informationLING 388: Computers and Language. Lecture 5
LING 388: Computers and Language Lecture 5 Administrivia Homework 3 graded Quick Homework 4 out today I'll be away next two weeks (my apologies) Colton Flowers, a HLT student, will take you through Python
More informationIntroduction to Computer Programming for Non-Majors
Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2015 Chapter 5 Part 3 & Review The Department of Computer Science Multi-Line Strings Files: Multi-line Strings A file is a sequence of
More informationCharacter Encodings. Fabian M. Suchanek
Character Encodings Fabian M. Suchanek 22 Semantic IE Reasoning Fact Extraction You are here Instance Extraction singer Entity Disambiguation singer Elvis Entity Recognition Source Selection and Preparation
More informationRegular Expressions. Todd Kelley CST8207 Todd Kelley 1
Regular Expressions Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 POSIX character classes Some Regular Expression gotchas Regular Expression Resources Assignment 3 on Regular Expressions
More informationFiles. Files need to be opened in Python before they can be read from or written into Files are opened in Python using the open() built-in function
Files Files File I/O Files need to be opened in Python before they can be read from or written into Files are opened in Python using the open() built-in function open(file, mode='r', buffering=-1, encoding=none,...
More informationPython Working with files. May 4, 2017
Python Working with files May 4, 2017 So far, everything we have done in Python was using in-memory operations. After closing the Python interpreter or after the script was done, all our input and output
More informationBlack Problem 2: Huffman Compression [75 points] Next, the Millisoft back story! Starter files
Black Problem 2: Huffman Compression [75 points] Copied from: https://www.cs.hmc.edu/twiki/bin/view/cs5/huff manblack on 3/15/2017 Due: 11:59 PM on November 14, 2016 Starter files First, here is a set
More informationVariables, Constants, and Data Types
Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types
More information2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme
2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme repeated (integer) division by two. Example: What is
More informationFinal Exam Practice Questions
Final Exam Practice Questions Note that while these questions are great practice for the final exam, they do not necessarily cover ever topic or question type that could appear on the exam. You are strongly
More information1. Which of the following Boolean operations produces the output 1 for the fewest number of input patterns?
This is full of Test bank for Computer Science An Overview 12th Edition by Brookshear SM https://getbooksolutions.com/download/computer-science-an-overview-12th-editionby-brookshear-sm Test Bank Chapter
More informationChapter 6: Files and Exceptions. COSC 1436, Spring 2017 Hong Sun 3/6/2017
Chapter 6: Files and Exceptions COSC 1436, Spring 2017 Hong Sun 3/6/2017 Function Review: A major purpose of functions is to group code that gets executed multiple times. Without a function defined, you
More informationIntroduction to Computer Programming in Python Dr. William C. Bulko. Data Types
Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have
More informationTopic 2. Big C++ by Cay Horstmann Copyright 2018 by John Wiley & Sons. All rights reserved
Topic 2 1. Reading and writing text files 2. Reading text input 3. Writing text output 4. Parsing and formatting strings 5. Command line arguments 6. Random access and binary files Reading Words and Characters
More informationLecture #13: More Sequences and Strings. Last modified: Tue Mar 18 16:17: CS61A: Lecture #13 1
Lecture #13: More Sequences and Strings Last modified: Tue Mar 18 16:17:54 2014 CS61A: Lecture #13 1 Odds and Ends: Multi-Argument Map Python s built-in map function actually applies a function to one
More informationstreamio Documentation
streamio Documentation Release 0.1.0.dev James Mills April 17, 2014 Contents 1 About 3 1.1 Examples................................................. 3 1.2 Requirements...............................................
More informationStarting Out with Java: From Control Structures Through Objects Sixth Edition
Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 11 I/O File Input and Output Reentering data all the time could get tedious for the user. The data can be saved to
More informationUNIT IV-2. The I/O library functions can be classified into two broad categories:
UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known
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 informationCOMP 2718: The OS, Shell, Terminal, and Text
COMP 2718: The OS, Shell, Terminal, and Text By: Dr. Andrew Vardy Adapted from the notes of Dr. Rod Byrne Outline What is an Operating System? The Shell and Terminal How are Characters Encoded? Standard
More information25.2 Opening and Closing a File
Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:
More informationNumber Systems, Scalar Types, and Input and Output
Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of
More informationThis is a list of questions and answers about Unicode in Perl, intended to be read after perlunitut.
NAME Q and A perlunifaq - Perl Unicode FAQ This is a list of questions and answers about Unicode in Perl, intended to be read after perlunitut. perlunitut isn't really a Unicode tutorial, is it? No, and
More informationprint STDERR "This is a debugging message.\n";
NAME DESCRIPTION perlopentut - simple recipes for opening files and pipes in Perl Whenever you do I/O on a file in Perl, you do so through what in Perl is called a filehandle. A filehandle is an internal
More informationMULTIPLE CHOICE. Chapter Seven
Chapter Seven MULTIPLE CHOICE 1. Which of these is associated with a specific file and provides a way for the program to work with that file? a. Filename b. Extension c. File object d. File variable 2.
More informationDec. 16/ Deciding Which Loop to Use
Dec. 16/2013 - Deciding Which Loop to Use When is the while loop ideal to use? What is the do while loop ideal for? What is the for loop ideal for? What classes are used to write data to a file? What classes
More informationStorage Types Display Format String Numeric (Dis)connect Cha
Storage Types Display Format String Numeric (Dis)connect Characters Jeehoon Han jhan4@nd.edu Fall 2017 Storage Types Storage types Numbers (digits of accuracy) Integers: byte(2), int(4), long(9) Floating
More informationC H A P T E R 1. Introduction to Computers and Programming
C H A P T E R 1 Introduction to Computers and Programming Topics Introduction Hardware and Software How Computers Store Data How a Program Works Using Python Computer Uses What do students use computers
More informationJava Basic Datatypees
Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationProgramming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.
Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers
More informationStrings, characters and character literals
Strings, characters and character literals Internally, computers only manipulate bits of data; every item of data input can be represented as a number encoded in base 2. However, when it comes to processing
More informationCrash Dive into Python
ECPE 170 University of the Pacific Crash Dive into Python 2 Lab Schedule Today Ac:vi:es Endianness Python Thursday Network programming Lab 8 Network Programming Lab 8 Assignments Due Due by Mar 30 th 5:00am
More informationLoop structures and booleans
Loop structures and booleans Michael Mandel Lecture 7 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture07final.ipynb
More informationPYTHON- AN INNOVATION
PYTHON- AN INNOVATION As per CBSE curriculum Class 11 Chapter- 2 By- Neha Tyagi PGT (CS) KV 5 Jaipur(II Shift) Jaipur Region Python Introduction In order to provide an input, process it and to receive
More informationCPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation
CPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation George Tsiknis University of British Columbia Department of Computer Science Winter Term 2, 2015-2016 Last updated: 04/04/2016
More informationMemory, Data, & Addressing II CSE 351 Spring
Memory, Data, & Addressing II CSE 351 Spring 2018 http://xkcd.com/138/ Review Questions 1) If the word size of a machine is 64-bits, which of the following is usually true? (pick all that apply) a) 64
More informationFinal Exam. 11 May 2018, 120 minutes, 26 questions, 100 points
Name: CS520 Final Exam 11 May 2018, 120 minutes, 26 questions, 100 points The exam is closed book and notes. Please keep all electronic devices turned off and out of reach. Note that a question may require
More informationPython allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:
1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,
More informationContent. Information Coding. Where are we? Where are we? Bit vectors (aka Words )
Information Coding Lecturer: Guillaume Beslon Original Author: Lionel Morel Computer Science and Information Technology - INSA Lyon Fall 2018 1 / 36 2 / 36 Where are we? Where are we? Programmers......
More informationHardware: Logical View
Hardware: Logical View CPU Memory Bus Disks Net USB Etc. 1 Hardware: Physical View USB I/O controller Storage connections CPU Memory 2 Hardware: 351 View (version 0) instructions? Memory CPU data CPU executes
More informationJava language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS
Java language Part 1. Java fundamentals Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua What Java is? Programming language Platform: Hardware Software OS: Windows, Linux, Solaris,
More informationChapter 6: Files and Exceptions. COSC 1436, Summer 2016 Dr. Ling Zhang 06/23/2016
Chapter 6: Files and Exceptions COSC 1436, Summer 2016 Dr. Ling Zhang 06/23/2016 Introduction to File Input and Output Concept: When a program needs to save data for later use, it writes the data in a
More informationUTF and Turkish. İstinye University. Representing Text
Representing Text Representation of text predates the use of computers for text Text representation was needed for communication equipment One particular commonly used communication equipment was teleprinter
More informationJava characters Lecture 8
Java characters Lecture 8 Waterford Institute of Technology January 31, 2016 John Fitzgerald Waterford Institute of Technology, Java characters Lecture 8 1/33 Presentation outline Estimated duration presentation
More informationTECkit version 2.0 A Text Encoding Conversion toolkit
TECkit version 2.0 A Text Encoding Conversion toolkit Jonathan Kew SIL Non-Roman Script Initiative (NRSI) Abstract TECkit is a toolkit for encoding conversions. It offers a simple format for describing
More informationMISB ST STANDARD. 29 October Ancillary Text Metadata Sets. 1 Scope. 2 References. 3 Acronyms. 4 Definitions
MISB ST 0808.2 STANDARD Ancillary Metadata Sets 29 October 2015 1 Scope This standard (ST) defines the Ancillary Local Set and the Ancillary Universal Set. These sets include KLV metadata elements for
More informationAnnouncements COMP 141. Writing to a File. Reading From a File 10/18/2017. Reading/Writing from/to Files
Announcements COMP 141 Reading/Writing from/to Files Reminders Program 5 due Thurs., October 19 th by 11:55pm Solutions to selected problems from Friday s lab are in my Box.com directory (LoopLab.py) Programming
More informationPython Tutorial. Day 1
Python Tutorial Day 1 1 Why Python high level language interpreted and interactive real data structures (structures, objects) object oriented all the way down rich library support 2 The First Program #!/usr/bin/env
More informationRepresenting Characters and Text
Representing Characters and Text cs4: Computer Science Bootcamp Çetin Kaya Koç cetinkoc@ucsb.edu Çetin Kaya Koç http://koclab.org Winter 2018 1 / 28 Representing Text Representation of text predates the
More informationCHAPTER 3 Expressions, Functions, Output
CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number
More informationDirectory of C:\Users\Ami\Documents\Python Scripts
Chapter 8: Files and I/O Up to this point, all input and output has taken place using the keyboard and the command console. Specifically, the function input() has been used to collect user data, and the
More informationB.V. Patel Institute of BMC & IT, UTU 2014
BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we
More informationLecture 22. Java Input/Output (I/O) Streams. Dr. Martin O Connor CA166
Lecture 22 Java Input/Output (I/O) Streams Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics I/O Streams Writing to a Stream Byte Streams Character Streams Line-Oriented I/O Buffered I/O
More informationENGR/CS 101 CS Session Lecture 3
ENGR/CS 101 CS Session Lecture 3 Log into Windows/ACENET (reboot if in Linux) Start Microsoft Visual Studio 2010 Windows button -> All Programs -> 02 Programming -> Microsoft Visual Studio 2010 -> Microsoft
More informationBash command shell language interpreter
Principles of Programming Languages Bash command shell language interpreter Advanced seminar topic Louis Sugy & Baptiste Thémine Presentation on December 8th, 2017 Table of contents I. General information
More informationFundamentals of Python: First Programs. Chapter 4: Strings and Text Files
Fundamentals of Python: First Programs Chapter 4: Strings and Text Files Objectives After completing this chapter, you will be able to Access individual characters in a string Retrieve a substring from
More informationJava How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Data stored in variables and arrays is temporary It s lost when a local variable goes out of scope or when
More informationIntroduction to: Computers & Programming: Strings and Other Sequences
Introduction to: Computers & Programming: Strings and Other Sequences in Python Part I Adam Meyers New York University Outline What is a Data Structure? What is a Sequence? Sequences in Python All About
More informationM1 Computers and Data
M1 Computers and Data Module Outline Architecture vs. Organization. Computer system and its submodules. Concept of frequency. Processor performance equation. Representation of information characters, signed
More informationGood Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:
CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well
More informationI/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O
I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)
More informationIntroduction. Arizona State University 1
Introduction CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 1 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationpylatexenc Documentation
pylatexenc Documentation Release 1.2 Philippe Faist Apr 28, 2017 Contents: 1 Simple Parser for LaTeX Code 3 1.1 The main LatexWalker class....................................... 3 1.2 Exception Classes............................................
More informationBuilding a Test Suite
Program #3 Is on the web Exam #1 Announcements Today, 6:00 7:30 in Armory 0126 Makeup Exam Friday March 9, 2:00 PM room TBA Reading Notes (Today) Chapter 16 (Tuesday) 1 API: Building a Test Suite Int createemployee(char
More information#11: File manipulation Reading: Chapter 7
CS 130R: Programming in Python #11: File manipulation Reading: Chapter 7 Contents File manipulation Text ASCII files Binary files - pickle Exceptions File manipulation Electronic files Files store useful
More informationExercise: The basics - variables and types
Exercise: The basics - variables and types Aim: Introduce python variables and types. Issues covered: Using the python interactive shell Creating variables Using print to display a variable Simple arithmetic
More informationAdvanced Python. Executive Summary, Session 1
Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.
More informationSlide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng
Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide
More informationChapter 3: Creating and Modifying Text
Chapter 3: Creating and Modifying Text Chapter Learning Objectives Which of the statements below is true after these two statements are executed? (Can be more than one.) 1)Variable a is now empty 2)Variable
More informationFile Input/Output in Python. October 9, 2017
File Input/Output in Python October 9, 2017 Moving beyond simple analysis Use real data Most of you will have datasets that you want to do some analysis with (from simple statistics on few hundred sample
More informationBCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer
BCH339N Systems Biology/Bioinformatics Spring 2018 Marcotte A Python programming primer Python: named after Monty Python s Flying Circus (designed to be fun to use) Python documentation: http://www.python.org/doc/
More informationVariables and Literals
C++ By 4 EXAMPLE Variables and Literals Garbage in, garbage out! To understand data processing with C++, you must understand how C++ creates, stores, and manipulates data. This chapter teaches you how
More informationChapter 11 Input/Output (I/O) Functions
EGR115 Introduction to Computing for Engineers Input/Output (I/O) Functions from: S.J. Chapman, MATLAB Programming for Engineers, 5 th Ed. 2016 Cengage Learning Topics Introduction: MATLAB I/O 11.1 The
More informationCSB541 Network Programming 網路程式設計. Ch.2 Streams 吳俊興國立高雄大學資訊工程學系
CSB541 Network Programming 網路程式設計 Ch.2 Streams 吳俊興國立高雄大學資訊工程學系 Outline 2.1 Output Streams 2.2 Input Streams 2.3 Filter Streams 2.4 Readers and Writers 2 Java I/O Built on streams I/O in Java is organized
More informationFile I/O in Python Formats for Outputs CS 8: Introduction to Computer Science, Winter 2018 Lecture #12
File I/O in Python Formats for Outputs CS 8: Introduction to Computer Science, Winter 2018 Lecture #12 Ziad Matni Dept. of Computer Science, UCSB Administrative Homework #7 is DUE on MONDAY (3/12) Lab
More information1 Strings (Review) CS151: Problem Solving and Programming
1 Strings (Review) Strings are a collection of characters. quotes. this is a string "this is also a string" In python, strings can be delineated by either single or double If you use one type of quote
More informationUNIVERSITÀ DI PADOVA. < 2014 March >
UNIVERSITÀ DI PADOVA < 2014 March > Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. Easy-to-read: Python code is much more clearly defined and visible
More informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
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 informationChapter 4: Computer Codes. In this chapter you will learn about:
Ref. Page Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence Ref. Page
More informationA Python programming primer for biochemists. BCH364C/394P Systems Biology/Bioinformatics Edward Marcotte, Univ of Texas at Austin
A Python programming primer for biochemists (Named after Monty Python s Flying Circus& designed to be fun to use) BCH364C/394P Systems Biology/Bioinformatics Edward Marcotte, Univ of Texas at Austin Science
More informationPython. Executive Summary
Python Executive Summary DEFINITIONS OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or response to operators). Everything in Python is an object. "atomic"
More informationIntroduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang
Introduction to C CMSC 104 Spring 2014, Section 02, Lecture 6 Jason Tang Topics History of Programming Languages Compilation Process Anatomy of C CMSC 104 Coding Standards Machine Code In the beginning,
More informationThe current topic: Python. Announcements. Python. Python
The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax
More information1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100?
1 CS 105 Review Questions Most of these questions appeared on past exams. 1. What is the minimum number of bits needed to store a single piece of data representing: a. An integer between 0 and 100? b.
More informationlibsegy Programmer s Reference Manual
libsegy Programmer s Reference Manual Nate Gauntt Last Modified: August 11, 2008 Contents 1 Introduction 2 2 Why Use libsegy? 2 3 Building and Installation 3 3.1 Building C-Library Interface.....................
More informationDATA STRUCTURE AND ALGORITHM USING PYTHON
DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting
More information