Files in Python - cs.engr.uky.edu

Files in Python - cs.engr.uky.edu

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 them More than this, you need an external file stored on secondary storage

External data files Handles large amounts of data Data is independent of program, so program can change without changing data Easier to edit data in an editor, instead of during run of program (cant go back!) Use the same data for input to different programs Output files can be saved for later use

Output of one program can be used for input of another Text files versus Binary files Text files created by editors, stored as ASCII codes Binary files stored as raw binary numbers, have to be handled differently Text files are manipulated sequentially only

Binary files can be manipulated sequentially or randomly (we will not do binary files in this class) Creating a text data file This is done just like creating any other text file You can use Notepad You can use the editors of the IDEs that create Python

You can use a word processor like Word if you are careful to save as plain text Store the text file in the same folder as you put your source code Delimiters The \n (newline) (carriage return) is a very important symbol in text files. It delimits what Python calls a line in the file.

It gets put into the file whenever you press Enter at the end of a line A blank line is represented by two newlines together \ n\n It matters whether you press Enter at the end of the last line of the file some methods in Python will treat the last line differently because of the \n character

Recently Viewed Presentations

  • uod-school-education

    uod-school-education

    Student Attainment and Experience Conference University of Derby What are students' perceptions of learning support for their hidden disabilities in higher education classrooms?
  • Supply Chain Management Systems - Siena

    Supply Chain Management Systems - Siena

    Supply Chain Management Systems Lindsey Palmiotto Deanna Nicastro What is Supply Chain Management? A cross functional system using information technology to help manage some of a company's key business processes such as those of its suppliers, customers, and other business...
  • Hamid Vakilzadian - West Area Chair

    Hamid Vakilzadian - West Area Chair

    Title: Hamid Vakilzadian - West Area Chair Last modified by: Bob Parro Document presentation format: On-screen Show Other titles: Times New Roman Arial Century Arial Unicode MS Comic Sans MS 굴림 Symbol Arial Black Lucida Sans Unicode StarSymbol 1_Default Design...
  • Section 4.5 - cbafaculty.org

    Section 4.5 - cbafaculty.org

    Mehta, Danielson, & Berg Lecture Notes for Section 4.5. 1. D. 2. A. With the force P, a person is creating a moment M A using this flex-handle socket wrench. Does all of M A act to turn the socket?...
  • READING COACHES: What Are They & What Do They Do?

    READING COACHES: What Are They & What Do They Do?

    What Do Reading Coaches Do? OBSERVE reading lessons & provide feedback COLLECT DATA on students & teachers ADVISE & SUPPORT teachers to improve reading/literacy lessons (materials, instruction, assessments) What do YOU DO as a reading coach, or What do you...
  • VSEPR PowerPoint - Tetrahedral, Trigonal Bipyramidal, etc.

    VSEPR PowerPoint - Tetrahedral, Trigonal Bipyramidal, etc.

    Valence Shell Electron Pair Repulsion Theory Tetrahedral Trigonal pyramidal Bent
  • Torque  Torque in 2 and 3 dimensions Text

    Torque Torque in 2 and 3 dimensions Text

    Physics 1D03 - Lecture 10 * An unbalanced force applied to an object causes it to move (accelerate). F a Even with no net force, the object is not necessarily in equilibrium. A net torque will cause it to rotate....
  • Influence of Regional Transport on San Antonio Ozone

    Influence of Regional Transport on San Antonio Ozone

    GEOS-Chem model can capture ozone variability in San Antonio and shows a good performance in ozone vertical distribution. Marine air intrusions from the Gulf can reduce the ozone concentration in San Antonio, which shows the influence of regional transport on...