bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Python/Reference and Practice
Python•Reference and Practice

Python File Methods

Flash cards

Review the key moves

1/3
Core idea

What is the main idea behind Python File Methods?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

Python has a set of methods available for the file object.

MethodDescription
close()Closes the file
detach()Returns the separated raw stream from the buffer
fileno()Returns a number that represents the stream, from the operating system's perspective
flush()Flushes the internal buffer
isatty()Returns whether the file stream is interactive or not
read()Returns the file content
readable()Returns whether the file stream can be read or not
readline()Returns one line from the file
readlines()Returns a list of lines from the file
seek()Change the file position
seekable()Returns whether the file allows us to change the file position
tell()Returns the current file position
truncate()Resizes the file to a specified size
writable()Returns whether the file can be written to or not
write()Writes the specified string to the file
writelines()Writes a list of strings to the file

Learn more about the file object in our Python File Handling Tutorial .

Previous

Python Set Methods

Next

Python Keywords