Python Forum
how hard is it to emulate print() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how hard is it to emulate print() (/thread-12713.html)



how hard is it to emulate print() - Skaperen - Sep-09-2018

how hard is it to emulate the print() function? i have a thing which i want code to be made like it is printing. but the thing gets the lines that be printed and goes things with it. or should i use that thing that lets you print to a string (is it a generator)?


RE: how hard is it to emulate print() - Windspar - Sep-09-2018

Not hard to emulate print.

import time
from sys import stdout, version_info
V = version_info

def tick():
    if V.major == 3 and V.minor > 2:
        return time.perf_counter()
    else:
        return time.clock()

def main():
    string_buffer = list('Printing')
    intervals = 0.2
    clock = intervals + tick()
    while len(string_buffer):
        if  tick() > clock:
            stdout.write(string_buffer.pop(0))
            stdout.flush()
            clock += intervals

main()



RE: how hard is it to emulate print() - Skaperen - Sep-10-2018

what is that code supposed to do?