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

Recommended Answers

All 4 Replies

Can you post a full snippet replicating the error ?

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

Your code is really odd.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.