Description
Response number 1
Christopher Slone
Mar 18, 2021 at 3:34 PM
Hi Class,
For the week 3 discussion, we are going to look at utilizing functions to provide a way to clear Pythons integrated development environment (IDLE) window. This one was actually a bit of a challenge because I am more comfortable using notepad for writing my code and then using the built-in windows command prompt to call Python through the py command. In that environment, clearing a screen is as simple as typing cls and pressing the enter key, but unfortunately, this is not a command that the IDLE environment can recognize as demonstrated below.
>>> print (‘hello’)
hello
>>> cls
Traceback (most recent call last):
File “<pyshell#1>”, line 1, in <module>
cls
NameError: name ‘cls’ is not defined
>>>
Based on internet research, there are two different ways to get around this issue (without just manually closing the application and relaunching it from the start menu). The first solution really sounded more like a band aid so I will explain the purpose behind the function, but I dont suggest using it as a true fix. The basic function recommended was to use print (n * 100) which is basically printing 100 blank lines to clear off the screen.
>>> print (“n” * 100)
As mentioned above, I am really not a fan of this loop because it is simply adding 100 empty lines to push the text away to give the impression of a clear screen. After further research, I discovered that there is a more elegant way of doing this task by using the import os module. By calling this module, I can then use some of the standard commands that are built into the operating system, such as clear to clear the screen without inserting multiple blank lines.
>>> import os
>>> def cls():
os.system(“clear”)
>>> cls()
Response number 2
Matthew Glass
Mar 18, 2021 at 8:24 PM
Hello all,
I am honestly not really too sure what this post is even asking or what some of these terms means. After looking it up and reading through some other sites it seems there are multiple ways to go about clearing the IDLE window. The first way would be to call enough line breaks to clear out everything that was previously in the window. This would be done like
def cls():
print (“n” * 50)
I think this just prints a bunch of line breaks. I have read that another way would be pressing and holding Ctrl + J and then pressing enter but that may not always work depending what type of OS you are using. My main challenge with this task is understanding what it means. What is the point of doing something like this? Why would I need to clear the window? I am hoping reading some other responses clears it up for me because I am having a hard time with this one.