printing - Python print(foo, end = "") not working in terminal -
so code supposed print text, similar how pokemon does. purely fun.
the problem "print(x, end = "")" not work when program run in terminal, works fine when run using idle.
import time lorem = "lorem ipsum dolor sit amet, consectetur adipiscing elit. quisque id feugiat leo. quisque dictum, lectus dictum facilisis porttitor, diam dui sagittis nisl, et ultricies nisi dolor eget mauris. integer euismod aliquam imperdiet. nulla id orci elit. nulla quis viverra diam, in lobortis urna. integer lorem lectus, feugiat vel placerat et, ornare @ urna. praesent nec nisi venenatis, feugiat quam eget, tristique tellus. fusce in magna tincidunt, lacinia turpis eu, porta ex. phasellus ullamcorper, elit consectetur convallis imperdiet, nunc magna imperdiet nulla, quis porta dolor neque @ dolor. cras dolor nisl, tristique eget placerat vel, aliquet @ nisl. ut finibus interdum libero luctus." x in lorem: print(x, end = "") time.sleep(0.03)
for reason program works fine if put print statement before "print(x, end = "")".
for x in lorem: print() print(x, end = "") time.sleep(readspeed)
does have idea causing this? , maybe how fix it? thanks!!!
this happening because python uses buffer write stdout. in order desired effect, must put sys.stdout.flush() @ end of code...
import time, sys lorem = "lorem ipsum dolor sit amet, consectetur adipiscing elit. quisque id feugiat leo. quisque dictum, lectus dictum facilisis porttitor, diam dui sagittis nisl, et ultricies nisi dolor eget mauris. integer euismod aliquam imperdiet. nulla id orci elit. nulla quis viverra diam, in lobortis urna. integer lorem lectus, feugiat vel placerat et, ornare @ urna. praesent nec nisi venenatis, feugiat quam eget, tristique tellus. fusce in magna tincidunt, lacinia turpis eu, porta ex. phasellus ullamcorper, elit consectetur convallis imperdiet, nunc magna imperdiet nulla, quis porta dolor neque @ dolor. cras dolor nisl, tristique eget placerat vel, aliquet @ nisl. ut finibus interdum libero luctus." x in lorem: print(x, end = "") time.sleep(0.03) sys.stdout.flush()
this print out each character individually @ rate of 1 character per 0.03 seconds
Comments
Post a Comment