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 trialnicole lumpkin
Courses Plus Student 5,328 Pointsclear_screen() function in Workspace vs. Spyder IDE
This is my first time utilizing the os and sys modules and I've noticed some differences of their effect when used in Spyder's IPython console vs. TeamTreehouse's Workspace. For example:
The following code neatly exits/quits Kenneth's script.
sys.exit
However, in Spyder this is the result of that call
UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
An exception has occurred, use %tb to see the full traceback.
Mind you the script does quit, but the interpreter doesn't seem to like it. Finally, it seem that my clear functions are not having the same effect if any in Spyder as it does in Workspace. The following code is meant to clear the screen for an enhanced UI experience.
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
Nothing seems to be clearing. I guess I'm left a little lost on how this code would function in a standard IDE.
Thanks!
2 Answers
Brian Boring
Courses Plus Student 3,904 PointsThe os functions didn't work for me either when I started using PyCharm. I discovered that I had to run my programs in terminal using "python3 file_name.py" instead of just "python file_name.py" like I was doing in Workspaces, otherwise terminal would default to python 2. That fixed those issues for me, but not positive whether the same will work in your case. Worth a try.
nicole lumpkin
Courses Plus Student 5,328 PointsHey Randy Eichelberger yes I'm still around and yes I do have both Python 2 and 3 installed! Do go on!!!
nicole lumpkin
Courses Plus Student 5,328 Pointsnicole lumpkin
Courses Plus Student 5,328 Pointsokay thanks :)
Randy Eichelberger
1,491 PointsRandy Eichelberger
1,491 PointsI probably have an answer as to why this is if you're still around. Just let me know if you have both Python 2 and 3 installed.