Home ยป Blog ยป Learn how to code with python: Lesson 4 – Reading and writing files

Learn how to code with python: Lesson 4 – Reading and writing files

Working with files in Python
Working with files in Python

One of the most useful things to know how to do when just learning how to program is knowing how to read and write text files. In this video, I show you how to do just that.

Example code from the video:

>>> f = open(‘Desktop/lorumipsum.txt’)
>>> print(f)
<_io.TextIOWrapper name=’Desktop/lorumipsum.txt’ mode=’r’ encoding=’UTF-8′>
>>> f.readline()
‘Lorem ipsum dolor sit amet,….

>>> f.read()
‘nEtiam rhoncus….
…metus at tortor pulvinar varius.n’
>>>
>>> f = open(‘Desktop/lorumipsum.txt’)
>>> f.readlines()
[‘Lorem ipsum dolor…

For the next lesson click here.