Files in a nutshell
Download
1 / 7

Files in a Nutshell - PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on

Files in a Nutshell. Primary Vs. Second Storage. My Computer 8 GB RAM 1 TB Disk space Ram access time: nanosecond range Disk access time: millisecond range Ram is volatile Disk is not volatile. File Systems. The file system is a subsystem of the OS

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Files in a Nutshell' - media


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Primary vs second storage
Primary Vs. Second Storage

  • My Computer

    • 8 GB RAM

    • 1 TB Disk space

  • Ram access time: nanosecond range

  • Disk access time: millisecond range

  • Ram is volatile

  • Disk is not volatile


File systems
File Systems

  • The file system is a subsystem of the OS

  • All requests to read/write files are handled are passed through to the OS

  • A programming language—like Python— provides an interface to OS file system services


Python file services open close
Python File Servicesopen/close

  • Open

    • Tells the OS to return information about a particular file to the program

    • Tells the OS whether you want to read or write

  • Close

    • Tells the OS you are finished with a file

    • OS writes data from memory to secondary storage


Open close syntax
Open/Close Syntax

  • myFile = open(“fileName.txt”, “r”)

  • myFile = open(“fileName.txt”, “w”)

  • myFile.close()


Reading
Reading

  • Using the range function:

    >>myFile = open(“fileName”,”r”)

    >>for aline in myFile …

  • Read the entire file as a string

    >>myString = myFile.read()

  • Read n characters as a string

    >>myString = myFile.read(n)

  • Read a line into a string:

    >>myString = myFile.readline()

  • Read n lines into a list of n strings:

    >>myList = myFile.readine(n)


Writing
Writing

  • Adds a string to the end of a file. Creates the file if it does not already exist

    >> myFile.write(myString)


ad