class stdout(object):
    def __init__(self,realout,prefix):
        self.file = realout
        self.at_start_of_line = True
        self.prefix=prefix
    def write(self, text):
        if len(text):
            if self.at_start_of_line:
                text = self.prefix + text

            self.file.write(text)

            self.at_start_of_line = (text[-1] == '\n')
sys.stdout=stdout(sys.stdout,"OUT  ["+f+"]> ")




  File "C:\Users\James\Desktop\run.py", line 13, in write
    self.file.write(text)
  File "C:\Users\James\Desktop\run.py", line 10, in write
    if self.at_start_of_line:
  AttributeError: 'stdout' object has no attribute 'prefix'

It's not the whole thing but the error is really confusing

This looks like you are using class, not class instance, so the instance variable is not initialized.

Edited 3 Years Ago by pyTony

from subprocess import *
import sys
class stdout(object):
    def __init__(self,realout,prefix):
        self.file = realout
        self.at_start_of_line = True
        self.prefix=prefix
    def write(self, text):
        if len(text):
            if self.at_start_of_line:
                text = self.prefix + text

            self.file.write(text)

            self.at_start_of_line = (text[-1] == '\n')
sys.stdout=stdout(sys.stdout,"OUT  ["+f+"]> ")
while True:
    f = raw_input("URL:")
    p = Popen("C:/python27/python.exe "+f,shell=True)#,stdin=PIPE,stdout=PIPE,stderr=PIPE)
    print"Press enter to read from pipes"
    print"Press Control-C to terminate"
    while not p.poll():
        try:
            d = raw_input("IN   ["+f+"]> ")
            if d == '':
                d = None
            try:
                output,errors = p.communicate(d)
            except:
                pass
            if errors.strip():
                print "ERROR["+f+"]>"
                print errors
        except KeyboardInterrupt:
            print"Terminating..."
            p.terminate()
            print"Terminated."
            break
This question has already been answered. Start a new discussion instead.