TWiT Throwback (Audio)

Coding 101 16: Python - The External Data Circle of Life


Listen Later

Welcome to Coding 101 - It's the TWiT show that gives YOU the knowledge to live in the wonderful world of the programmer. This week we are introducing our newest module, Python with Code Warrior Dale Chase!

To see all the code used in today's episode, go to Our Github Repository for Module 2

Ivory Tower: External File IO

Using external data reqires knowledge of four functions: "open()", " read()", "write()" and "close()"

open()

This function opens a file with the flags and mode of your choosing. For simplicity, we're only using the "r" "w" modes.

  • The "r" mode opens a file for "read only" use
  • The "w" mode blanks the file prepares to write to the file
  • * Note that this function DOES NOT READ THE FILE INTO A VARIABLE.

    USAGE:

    text_file = open("/Users/PadreSJ/Desktop/C101-16/write.txt", "r")

    • This opens a file called "write.txt" in READ-ONLY mode and sets the pointer in variable "text_file"
    • text_file = open("/Users/PadreSJ/Desktop/C101-16/write.txt", "w")

      • This opens a file called "write.txt" in WRITE MODE, sets the pointer in variable "text_file" and blanks that file.
      • read()

        This function reads the contents of the file into a string variable.

        USAGE:

        textFromFile = text_file.read()

        • This reads the file at pointer "text_file" into the string variable "textFromFile"
        • write()

          This function writes a string into an external file.

          USAGE:

          text_file.write(MyString)

          • This writes the contents of the string variable "MyString" into the file indexed at "text_file"
          • close()

            This function closes access to the file. USAGE: text_file.close() #This closes the file indexed at "text_file"

            Hosts: Fr. Robert Ballecer, SJ and Shannon Morse

            Guest: Dale Chase

            Get in Touch With Us!
            • Subscribe and get Coding 101 automatically at https://twit.tv/shows/coding-101.
            • Follow PadreSJ and Snubs on Twitter
            • Bandwidth for Coding 101 is provided by CacheFly.

              Sponsors:

              • shutterstock.com offer code CODING514
              • squarespace.com offer code CODING
              • ...more
                View all episodesView all episodes
                Download on the App Store

                TWiT Throwback (Audio)By TWiT

                • 4
                • 4
                • 4
                • 4
                • 4

                4

                4 ratings


                More shows like TWiT Throwback (Audio)

                View all
                Total Leo (Audio) by TWiT

                Total Leo (Audio)

                202 Listeners

                TWiT News (Audio) by TWiT

                TWiT News (Audio)

                78 Listeners

                All TWiT.tv Shows (Audio) by TWiT

                All TWiT.tv Shows (Audio)

                355 Listeners

                TWiT Events (Audio) by TWiT

                TWiT Events (Audio)

                8 Listeners

                Total Mikah (Audio) by TWiT

                Total Mikah (Audio)

                3 Listeners

                Untitled Linux Show (Audio) by TWiT

                Untitled Linux Show (Audio)

                7 Listeners

                Host-Read Ads (Audio) by TWiT

                Host-Read Ads (Audio)

                3 Listeners