read() / readline() / readlines()

Dave Lajoie davelaj at videotron.ca
Wed Mar 9 23:01:57 EST 2005


Fyi, I found the answer ( at least one that still works )

def PrintThread(myThread):
    while myThread.isAlive() == True:
        line = p.stdout.readline()[:-1]
        if line == "":
                continue
        if line == '\0':
                break
        print line

Dave.
  ----- Original Message ----- 
  From: Dave Lajoie 
  To: Python-list at python.org 
  Sent: Wednesday, March 09, 2005 12:24 AM
  Subject: read() / readline() / readlines()


  Hello!
      would someone know a method that allows
      to read line delimited by "\n" instead of trapping "\0" like
      readlines does?

  I have to write my own while loop to do this.

      while myThread.isAlive() == True:
          myChar = p.stdout.read(1)
          if myChar == '\0':
              print "Found EOF, exiting!"
              break
          myStr = myStr + myChar
          if myChar == '\n':
                  print myStr
                  myStr = ""
                  continue

  is there a more elegant way to do this?
  tx
  Dave.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050309/60551209/attachment.html>


More information about the Python-list mailing list