title: Python - how to parse strings from an array?
body: <p>I'm a Java/C programming, struggling to learn Python.  (I'm writing in Python 2.4.3 on a Linux machine.)  I have a simple program which telnets to a Cisco router, logs in, then captures the config.  The router's config is stored in a variable named "output":</p>
  
  <pre><code>#!/usr/bin/python
  
  import telnetlib
  import datetime
  import sys
  
  def telnetFunction( host ):
    print("Telnetting to device "+host+"...\n")
    tn = telnetlib.Telnet(host)
    # ...use tn.read_until() and tn.write() to log into the router...  ...this works...
    tn.write("terminal length 0"+"\n")
    tn.write("show run"+"\n")
    tn.write("exit"+"\n")
    output=tn.read_all()      # router config stored as "output"
    return output
  
  host = "192.168.102.133"
  output=telnetFunction( host )
  </code></pre>
  
  <p>The above code works.  From using a bunch of different print() statements, I can see that the router's config is all in "output", which I am assuming is an array of newline-terminated strings....?  Not entirely sure about that; the telnetlib documentation doesn't specify.</p>
  
  <p>My problem now is I need my program to step through output again, extracting one string at a time.  I need something like:</p>
  
  <pre><code>while(iterating through output)
     tmpString = output.getNextStr()
  </code></pre>
  
  <p>So if output looked like this:</p>
  
  <pre><code>Current configuration : 34211 bytes\n!\nversion 12.3\nno service pad\n...etc...
  </code></pre>
  
  <p>I need tmpString to equal the follow in each iteration of the loop above:</p>
  
  <pre><code>tmpString = "Current configuration : 34211 bytes"
  tmpString = "!"
  tmpString = "version 12.3"
  tmpString = "no service pad"
  </code></pre>
  
  <p>I've been Googling for a few hours, but am stumped.  (Part of the problem is I'm not clear that "output" is indeed an array.  Could it be a string?)  I've played with split() and using []'s but no luck so far.  Does anyone see where I'm going wrong?  Thanks, -ROA</p>