Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJen Farrant
6,905 Pointsthe clear screen doesn't work.
I cannot get the clear screen function to work. I'm on a mac, and I've tried it the code in Idle and Thonny. It's not my code that's the issue, I've downloaded Kenny's code (which I presume works fine!) and I can't get that to work in Thonny or Idle either.
It's not just this section of the course, it is anytime that I use the clear function - it just doesn't work. I'm using the code for both mac and windows in my coding.
def clear():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
and as I said, even Kenny's code doesn't work, so I'm confident I haven't made an error
Any suggestions?
2 Answers
Viraj Deshaval
4,874 PointsIt will not work in IDLE or Thonny or any other python work ground because "os" library let's us use functionality on operating system level. To perform similar kind of thing in IDLE you can try this as below:
def clear():
print("\n" * 150)
clear()
print("Hello Treehouse")```
I hope I answered your query. Please let me know if you require any example.
Viraj Deshaval
4,874 PointsHi Jen, Thanks for reaching out to community. You need to import os module in order to use os functions. Just write "import os" without quotes of course and try it should work.
Jen Farrant
6,905 Pointssorry, should have been clearer - I'm already doing that further up the screen
Jen Farrant
6,905 PointsJen Farrant
6,905 PointsI did not know that.... thank you for letting me know, I can stop being extremely frustrated now!