wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, volunteer authors worked to edit and improve it over time.
This article has been viewed 14,957 times.
Learn more...
Text files can be super useful when coding in Python. You can retrieve information from text files using your code, and you can modify the information that is stored in a text file. In order to be able to do this, it is important to understand how to properly open the file, read the file or write in the file, and then finally save the changes you made (if you made any) to the file. This instruction set will teach you how to do this in a very simple way, and should take no longer than 10-15 minutes! These instructions will specifically discuss how to do this on a MacBook.
Steps
Download Python
-
1Open a browser and navigate to Python.org.
- This should take you to Python's website where you can download the latest version of Python available.
-
2Click the "Downloads" tab.
- Find where it says "Download the latest version for macOS".
- Click the yellow button to download the latest version of Python onto your MacBook.
Advertisement -
3
-
4
Write Your Code
-
1Decide what you would like to create in a Text File.
- For this example, The example below will demonstrate taking each line from a previously created file and printing every other line (every odd line) onto a new file.
-
2
-
3
-
4
-
5
-
6