What value does the readline () method return upon encountering end of file quizlet?
Upgrade to remove ads Show
Only SGD 41.99/year
Terms in this set (23)open() function used to get input from a file rather than from a user typing on a keyboard variable = open ('file.txt') methods to read text from a file are read() method returns the file contents as a string. The readlines() method returns a list of strings. file.readline(), returns a single line at a time, which is useful when dealing with large files where the entire file contents may not fit into the available system memory. variable = open ('file.txt') an optional parameter is to read up to a certain amount of bytes, put the number in as the parameter Iterating over the lines of a file. f = open('myfile.txt') for line in f: f.close() write to a file to store data permanently. file.write() method will add only string to a file Ex: read mode can be specified in the open() Read mode 'r' opens a file for reading. Output to a file is buffered by the interpreter use the \n character adjust buffering in open() open(buffering=0) turns off closing a file, or using file.flush will force the interpreter to flush the output buffer to disk he write() method does not immediately writes data to a file, why is this? output is buffered, thus there may be a delay between calling the write method and data being written to the disk. to interact with the computer's file system, a program must use functions supplied by the operating system bc he computer's os controls the file system files are found differently on differen operating systems, so it is good practice to utilize the os.path module, which contains many portable functions for handling file paths. tokens = 'C:\\Users\\BWayne\\tax_return.txt'.split(os.path.sep) separate the parts of the file code at the separator for that system, and os.path.join(the tokens list) os.walk() function 'walks' a directory tree The os.walk() function is used as the iterable object in a for loop that yields a 3-tuple for each iteration.WALK The first item dirname contains the path to the current directory. The second item subdirs is a list of all the subdirectories of the current directory. The third item files is a list of all the files residing in the current directory. A programmer might use os.walk() when when searching for specific files within a directory tree, and the exact path is unknown. Another common task is to filter files based on their file extensions (.pdf, .txt, etc), A with statement can be used to open a file, execute a block of statements, and automatically close the file when complete. se a with statement when opening files, to guarantee that the file is closed when no longer needed. When using a with statement to open a file, the file is automatically closed when the statements in the block finish executing. What does file.readline() do? ends at \n or an
actual new line what does file.read() do? the entire file is read and made into one single string including the characters \n at new lines what does file.readlines() do? the entire file is read into a list and includes the \n characters how do you get rid of \n or white space in a file that was read ( or other things) use the strip() function iterate over a file without white space before or after each line for
line in file: OR while line != '': OR while True: line.startswith( will see if a line starts with the character imputed and return True or False (?) open(file, mode) as
var creates a variable file object Sets found in the same folderCS 108: Intro to Computing 1.1-1.8, 2.1-2.6 Error…65 terms sietsenr Linux14 terms sietsenr CS 108 2.8, 3.1-3.5 string, list, dict Python43 terms sietsenr CS 108 3.6-3.9, 4.1-4.7 Boolean python22 terms sietsenr Other sets by this creatorSpanish Unit 4 - goodbyes; more emotions; 100-1000…53 terms sietsenr Spanish Unit 3 - days of week + random ASL stuff36 terms sietsenr Spanish Unit 1; numbers + letters129 terms sietsenr Spanish Unit 2; greetings + addressing people50 terms sietsenr Verified questionscomputer science The negation operator is A) Unary B) Binary C) Ternary D) None of the above Verified answer
computer science How can you use an IntVar object to determine whether a Checkbutton has been selected? Verified answer
computer science Write a program that asks for the name of a pole vaulter and the dates and vault heights (in meters) of the athlete’s three best vaults. It should then report, in order of height (best first), the date on which each vault was made and its height. Input Validation: Only accept values between 2.0 and 5.0 for the heights. Verified answer computer science What output is produced by the following code fragment? String m1, m2, m3; m1="Quest for the Holy Grail"; m2=m1.toLowerCase(); m3=m1+" "+m2; System.out.println (m3.replace('h', 'z')); Verified answer Recommended textbook solutionsFundamentals of Database Systems7th EditionRamez Elmasri, Shamkant B. Navathe 687 solutions
Service Management: Operations, Strategy, and Information Technology7th EditionJames Fitzsimmons, Mona Fitzsimmons 103 solutions
Information Technology Project Management: Providing Measurable Organizational Value5th EditionJack T. Marchewka 346 solutions
Starting Out with Python4th EditionTony Gaddis 629 solutions Other Quizlet setsComputer Apps Final Exam48 terms Anpzzino44 MIS Final96 terms samburns1999 Productivity Software 2019-160 terms Jonnys17 Comp Sci Chapter 4 Theory Test- Sections 4.5 & 4.619 terms sc921 Related questionsQUESTION A _ is a collection of forms, reports, queries, and programs that serves as an intermediary between users and database data? 2 answers QUESTION 5. If a nonessential service is slowing down startup, how can you permanently disable it? 10 answers QUESTION If application software has stopped responding and the hard disk's LED blinks repeatedly, the operating system probably is doing this. 4 answers QUESTION Restricting the order of reads and writes to a particular location is called: 2 answers What is returned when the readline method reaches the end of the file?The readline method reads one line from the file and returns it as a string. The string returned by readline will contain the newline character at the end. This method returns the empty string when it reaches the end of the file.
Which method will return an empty string when it has attempted to read beyond the end of?Note that the readline method returns an empty string ( "" ) when it attempt to read beyond the end of the file.
What is the purpose of closing a file closing a file disconnects the program from the file?It is important to close files you are working with as soon as you are finished with them. This minimizes the amount of user virtual machine resources required and helps keep shared files and directories available for other users. Closing a file means logically disconnecting it from the application program.
What is the process of retrieving data from a file called?Data recovery is the process of restoring data that has been lost, accidentally deleted, corrupted or made inaccessible. In enterprise IT, data recovery typically refers to the restoration of data to a desktop, laptop, server or external storage system from a backup.
|