Lesson 8
Making Objects the Main Star!
Chapter 9: Reading and writing files
Related methods and modules
File objects have several other methods like .tell()
(where is the current position of the file pointer?) and .seek()
(go to certain positions in the file). We will not discuss them as you will probably not use these much. You can refer to the official documentation to learn more.
There are also some modules in the Python Standard Library that might be useful for working with directories and files:
- The
tempfile
module that is useful for creating temporary files (without a specific filename) - The
shutil
module provides a high level utlities to operate on files. For example, seeshutil.copy()
andshutil.move()
. - The
os
module contains useful low-level functions for manipulating files and directories. For example, seeos.listdir()
,os.makedirs()
,os.getcwd()
,os.rename()
,os.remove()
. - The
os.path
module contains useful functions for dealing with pathnames. For example, seeos.path.exists()
,os.path.join()
,os.path.basename()
,os.path.isdir()
. - The
pathlib
module provides an object-oriented implementation of some of the functions inos
andos.path
.
I will not discuss these in detail either. I am confident enough that you will be able to explore and use these on your own, especially when you need them!