title: Python telnetlib: surprising problem
body: <p>I am using the Python module telnetlib to create a telnet session (with a chess server), and I'm having an issue I really can't wrap my brain around. The following code works perfectly:</p>
  
  <pre><code>&gt;&gt;&gt; f = login("my_server") #code for login(host) below.
  &gt;&gt;&gt; f.read_very_eager()
  </code></pre>
  
  <p>This spits out everything the server usually prints upon login. However, when I put it inside a function and then call it thus:</p>
  
  <pre><code>&gt;&gt;&gt; def foo():
  ...   f = login("my_server")
  ...   return f.read_very_eager()
  ...
  &gt;&gt;&gt; foo()
  </code></pre>
  
  <p>I get nothing (the empty string). I can check that the login is performed properly, but for some reason I can't see the text. So where does it get swallowed?</p>
  
  <p>Many thanks.</p>
  
  <p>For completeness, here is login(host):</p>
  
  <pre><code>def login(host, handle="guest", password=""):
  try:
      f = telnetlib.Telnet(host) #connect to host
  except:
      raise Error("Could not connect to host")
  f.read_until("login: ")
  try:
      f.write(handle + "\n\r")
  except:
      raise Error("Could not write username to host")
  if handle == "guest":
      f.read_until(":\n\r")
  else:
      f.read_until("password: ")
  try:
      f.write(password + "\n\r")
  except:
      raise Error("Could not write password to host")
  return f
  </code></pre>