Hey guys, first time poster, relatively long time reader -- I am struggling creating a buffer class in python for my class. (relatively new to the language).
Here is the basic idea I want to do:
Implement a class that buffers text. The write() method adds a string to the buffer. If the added data contains a '*', print the buffer contents to the console up until and including the '*'.
Example use:
buffer = Buffer()
buffer.write ('abcd') # prints nothing
buffer.write ('ef*gh') # prints abcdef*
buffer.flush () # prints gh
I get the basic idea, of how to call this stuff up, but I am definitely struggling getting in concatenating the strings within the script itself -- and having the program do what it requested.
Here is my script as it stands, with real and psuedo code. I know it's something really simple and I've run around this for probably twice as long as I should and I just need to move on. Any pushes or help in the right direction would be GREATLY appreciated! Thanks so much! (For whatever reason, the forum is not indenting the code properly, but its set up properly in my code, so no worries about that.)
class StringBuffer:
def write(self, input):
s = input
t = s
if '*' in input:
input += t
# input = input.'do not print anything that comes after the *, but retain it)
print input
else:
s += t
#just keep concatenating until we have a * call
def flush(self):
print input.#'print anything after the *'
del input