PDF download Download Article PDF download Download Article

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.

Part 1
Part 1 of 3:

Download Python

PDF download Download Article
  1. 1
    Open 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.
  2. Advertisement
  3. 3
  4. 4
  5. Advertisement
Part 2
Part 2 of 3:

Write Your Code

PDF download Download Article
  1. 1
    Decide 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. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. Advertisement
Part 3
Part 3 of 3:

Run Your Program

PDF download Download Article
  1. 1
    Make sure that every file you used is in the same folder.
    • This includes the file that your code is written on.
  2. 2
  3. Advertisement

Expert Q&A

Ask a Question
      Advertisement

      Tips


      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 28,768 times.

      Is this article up to date?

      Advertisement