title: Could someone help me Understand ex23 in Zed Shaw's Learn Python 3 the Hard way
body: <p>I'm trying to decipher Zed's ex23 and his explanation is somewhat helpful but I'm getting lost. This script deals with him trying to teach you how to decode and encode letters in different languages it seems. A few of these topics seem premature/ he didn't go over it yet, and he mentions that this is on the harder end than anything I've seen but I'm getting consistently lost. I'll try and explain what I can based on what I see, but I am unsure if I understand everything here.</p>
  <pre><code>import sys script, input_encoding, error = sys.argv
  </code></pre>
  <p>This is simple, we are just importing sys and defining argv's variables.</p>
  <pre><code>def main(language_file, encoding, errors):
      line = language_file.readline() 
  </code></pre>
  <p>Defining the function titled main with three variables . Define line to read the line off the language file. How is language_file being defined? I don't see a definition anywhere?</p>
  <pre><code>if line:
      print_line(line, encoding, errors)  
      return main(language_file, encoding, errors)
  </code></pre>
  <p>The if line has something from what it is defined to be it will run the below. If it does not (AKA if it's false), then it won't. How can I get away with creating an if statement without defining the function in it above? Is there something I'm missing. Zed defined print_line below but uses it above? What does return main do? Does it mean that we return back to the base function?</p>
  <pre><code>def print_line(line, encoding, errors):
      next_lang = line.strip()  
      raw_bytes = next_lang.encode(encoding,
                                   errors=errors)
  </code></pre>
  <p>We are defining print_line here. What does the strip function do? What does errors=errors mean?</p>
  <pre><code> cooked_string = raw_bytes.decode(encoding, errors=errors) 
  </code></pre>
  <p>cooked_string we are defining as taking the raw bytes and encoding it...I think?</p>
  <pre><code>    print(raw_bytes, &quot;&lt;==&gt;&quot;, cooked_string)
  
  
  languages = open(&quot;languages.txt&quot;, encoding = &quot;utf - 8&quot;)
  </code></pre>
  <p>Why is it languages vs language_file?</p>
  <pre><code>main(languages, input_encoding, error)
  </code></pre>
  <p>I think this exercise is a bit premature in this book or I'm just not seeing something. Any help to dissect this would be greatly appreciated.</p>
  <p>Here is the full scrip uninterrupted without my comments:</p>
  <pre><code>def main(language_file, encoding, errors):
      line = language_file.readline() #defining line as a read off of language_file
  
  
      if line: # if line has something from what it is defined to be it will run the below. If it does not (AKA if it's false), then it won't.
          print_line(line, encoding, errors)  
          return main(language_file, encoding, errors)
  
  def print_line(line, encoding, errors):
      next_lang = line.strip()  # what is strip?
      raw_bytes = next_lang.encode(encoding, errors=errors) 
      cooked_string = raw_bytes.decode(encoding, errors=errors) 
  
      print(raw_bytes, &quot;&lt;==&gt;&quot;, cooked_string)
  
  
  languages = open(&quot;languages.txt&quot;, encoding = &quot;utf - 8&quot;)
  
  main(languages, input_encoding, error)
  </code></pre>