how do i clear the screen in python just like we do using (clrscr) in c+? I have just started ......
I don't know of a built in command but you could do something like: print '\n' * 70 Or stick that in a function called clrscr.
sry. this what it comes up when i enter clrscr or print '\n' * 70 : >>> clrscr Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> clrscr NameError: name 'clrscr' is not defined >>> '\n'*70 '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' >>> print '\n'*70 SyntaxError: invalid syntax (<pyshell#10>, line 1) is there any other way. thanx in advance. ?
Can you enter: print '\n' ? That should print one new line. If that works you can print many new lines by printing many \n's.
Just print in Python generates a new line, i.e., for i in xrange(NUMBEROFNEWLINES): print
Something like this may help: def clearscreen(numlines=100): """Clear the console. numlines is an optional argument used only as a fall-back. """ import os if os.name == "posix": # Unix/Linux/MacOS/BSD/etc os.system('clear') elif os.name in ("nt", "dos", "ce"): # DOS/Windows os.system('CLS') else: # Fallback for other operating systems. print '\n' * numlines
Join our real-time social learning platform and learn together with your friends!