1 / 7

Files in a Nutshell

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

media
Download Presentation

Files in a Nutshell

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Files in a Nutshell

  2. 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

  3. 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

  4. 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

  5. Open/Close Syntax • myFile = open(“fileName.txt”, “r”) • myFile = open(“fileName.txt”, “w”) • myFile.close()

  6. 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)

  7. Writing • Adds a string to the end of a file. Creates the file if it does not already exist >> myFile.write(myString)

More Related