Clear Screen in Python | How to Clear Terminal/Console in Python

  Рет қаралды 34,071

Fabio Musanni - Programming Channel

Fabio Musanni - Programming Channel

Күн бұрын

💻 Get my Source Codes and support the channel ❤️: www.buymeacoff...
⬇️ LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW) 😉💪 ⬇️
☕ Buy me a coffee: www.buymeacoff...
😍 One-off donation: www.paypal.me/...
SKILLSHARE
(Python, Web Dev, UI/UX Design, Music, Art, Animation and a lot more)
🔗 skillshare.eqc... (Affiliate)
DATACAMP
(Python, ChatGPT, SQL, Power BI, and a lot more)
🔗 datacamp.pxf.i... (Affiliate)
COURSERA PYTHON
(For beginners, Data Science, Data Analysis, AI, Cybersecurity and a lot more):
🔗 imp.i384100.ne... (Affiliate)
COURSERA WEB DEVELOPMENT
(Full Stack, Front-End, Back-End, Web Design and a lot more):
🔗 imp.i384100.ne... (Affiliate)
Learn how to clear the screen (terminal or console) with the right command by detecting automatically which operating system the user is using.
Instead of just overwriting the previous line we clear the whole terminal so that you can show a completely different thing to the user.
If the video was helpful, let me know in the comments down below and also like the video so that other people can see it. Needles to say I really appreciate your support 💪❤️
📨 SUBSCRIBE so that you don't miss any new video:
www.youtube.co...
🤗 BIO PAGE (contacts, etc): solo.to/fabiom...
Create Your Bio Page (10% OFF Upgraded Plans 😉): solo.to/inv/ND...
🔗 RELATED CONTENT (videos, playlists, etc) 🔗
Overwrite Previous Printed Line Video: • How to Overwrite Previ...
Python Playlist: • 🐍 Learn Python With Fa...
🤩 AFFILIATE LINKS 🤩
Create Your Bio Page (10% OFF Upgraded Plans): solo.to/inv/ND...
🧑🏻‍💻 ABOUT ME 🧑🏻‍💻
I'm Fabio, I started programming with Python a lot of years ago and I fell in love with this world.
I started this KZbin channel to help you during your own journey and I hope that my help can make you an amazing programmer who loves this world as I do.
Welcome on board!! 🚀
#pythonWithFabioMusanni #python #pythonforbeginners #pythontutorial #pythonprogramming #coding #programming

Пікірлер: 37
@FabioMusanni
@FabioMusanni 2 жыл бұрын
⬇️ *LEARN ON THE BEST LEARNING PLATFORMS (LINKS BELOW)* 😉💪 ⬇️ ☕ *Buy me a coffee:* www.buymeacoffee.com/fabiomusanni ❤️ *Support me monthly:* www.patreon.com/FabioMusanni 😍 *One-off donation:* www.paypal.me/FabioMusanni/ *SKILLSHARE* _(Python, Web Dev, UI/UX Design, Music, Art, Animation and a lot more)_ 🔗 skillshare.eqcm.net/5gxzD2 (Affiliate) *DATACAMP* _(Python, ChatGPT, SQL, Power BI, and a lot more)_ 🔗 datacamp.pxf.io/vN1bDj (Affiliate) *COURSERA PYTHON* _(For beginners, Data Science, Data Analysis, AI, Cybersecurity and a lot more):_ 🔗 imp.i384100.net/k0Nk60 (Affiliate) *COURSERA WEB DEVELOPMENT* _(Full Stack, Front-End, Back-End, Web Design and a lot more):_ 🔗 imp.i384100.net/EKWxBW (Affiliate) Thank you for the support!❤ 🎥All my videos about Python: kzbin.info/aero/PLs8qUrmRvaR0IT4IwJl-LSweAdACW-yLK
@osamahalghamdi9888
@osamahalghamdi9888 8 ай бұрын
If you're wondering how he added a # to all the lines, he use (Ctrl + /) after highlighting the desired lines.
@dawn3562
@dawn3562 Жыл бұрын
Exactly what I what looking for, Thanks!
@FabioMusanni
@FabioMusanni Жыл бұрын
Glad it was helpful and thank you for the comment 😉💪
@fruko3164
@fruko3164 2 жыл бұрын
it worked thanks!
@FabioMusanni
@FabioMusanni 2 жыл бұрын
Hi Fruko. Glad it helped 👍☺️
@zeeroslo
@zeeroslo 10 ай бұрын
I still cant seem to find the "Emulate terminal in output console" in the popup.
@FabioMusanni
@FabioMusanni 10 ай бұрын
It should be there, they maybe moved it inside the "Modify Options", you can see a picture here: www.jetbrains.com/help/pycharm/2023.3/run-debug-configuration.html#9c4548a2 And here you still have it in the table: www.jetbrains.com/help/pycharm/2023.3/run-debug-configuration.html#9ceaa53a Try having a look there and see if you can find something 😊
@MouseGoat
@MouseGoat 7 ай бұрын
Thanks for the video. Really helped me out with my project.
@FabioMusanni
@FabioMusanni 7 ай бұрын
Thank you for the comment! Really appreciated! 🤗😍 Remember that you can support the channel and also get the source code of my videos here: www.buymeacoffee.com/fabiomusanni
@technicalgyaan5528
@technicalgyaan5528 2 жыл бұрын
Is there no command like 'clrscr() in C'
@FabioMusanni
@FabioMusanni 2 жыл бұрын
Hello, good question but unfortunately in Python there is no such command 😊
@misba5785
@misba5785 Жыл бұрын
Is there any way I can undo and go get back my screen. I have used this while I created a menu within a menu. So the main menu asks the user to select 4 options when the user select one option, he gets clear screen and then moves on to one of those 4 options. But what if the user wants to undo, and go back to the main menu to again select one of those 4 options. I tried using subprocess thing in a function then giving if user input is q, I call my main menu or else if user enters he gets clear screen. But when user inputs q he is gonna press enter so anyways screen will be cleared. What if I want to undo it?
@FabioMusanni
@FabioMusanni Жыл бұрын
Hello 😊 There is no way to undo that command, once the terminal is cleared you can't go back. The only way to do what you are asking is to re-print the whole menu. Maybe you could create a function for the main menu and a function for the secondary menu, when the user is on the secondary menu and enters let's say "b" as in "back" you can clear the screen and call the function for the main menu so the user is shown the main menu and so on. I've made a video on menus, you can have a look at that, it's definitely going to help you a little (kzbin.info/www/bejne/kHPbaKKNeK9nl7s). In that video I don't clear the terminal but you can just clear the terminal every time you call the menu function.
@shirmilwelgama8521
@shirmilwelgama8521 Жыл бұрын
Thanks dude nice video !!!
@FabioMusanni
@FabioMusanni Жыл бұрын
Thank you for the comment man! Really appreciated! 🤗💪
@jihadnawzad8899
@jihadnawzad8899 Жыл бұрын
that is not working for me even with writing cls instead of clear. help me please
@FabioMusanni
@FabioMusanni Жыл бұрын
Hello, which code editor are you using? Pycharm?
@Magnymbus
@Magnymbus Жыл бұрын
TIL you can do this much easier. import os os.system("cls||clear") That's it. Two lines.
@FabioMusanni
@FabioMusanni Жыл бұрын
Hello 😊 Thanks for the comment. You can use os.system but since subprocess is newer, does the same things as os.system and in the docs is the recommended module to use, if two things do the same thing, I always use the one that is recommended. Using os.system doesn't really add value, you can still use "cls||clear" with subprocess and you'll have two lines as well. However, to me writing the code to check the operating system and then run the right command looks better and clearer, especially for beginners. So use the command that makes more sense to you, keeping in mind that subprocess does the same as os.system and more😊
@youngneji920
@youngneji920 Жыл бұрын
It doesn't work for me in pycharm :
@FabioMusanni
@FabioMusanni Жыл бұрын
Hello 😊 A person had the same problem a while ago, I'm going to paste here the reply I wrote back then: I've researched a bit and it seems that certain OS commands don't work in PyCharm because it's an IDE. This definitely works in the terminal, which is the most important thing, since people run programs from the terminal. If you want it to work in PyCharm as well you should enable one thing: Run --> Edit Configurations --> In the Popup, under execution, you need to enable "Emulate terminal in output console" After this everything should work in PyCharm too. 😉
@LiebredelMusgo
@LiebredelMusgo 4 ай бұрын
@@FabioMusanni thanks! it works in pycharm :)
@FabioMusanni
@FabioMusanni 4 ай бұрын
@@LiebredelMusgo Glad it worked!! 😊💪
@sirazulhaque1929
@sirazulhaque1929 Жыл бұрын
Can I run this clear command using the widgets button? Thanks!
@FabioMusanni
@FabioMusanni Жыл бұрын
Hello 😊 Are you creating a GUI program? If so, all the things in the GUI are not actually in the terminal but in other widgets, you should delete the text contained in the widget, not in the terminal. Anyway, if you still want to do it, in the video I show you how to create a function, you can use that function as the action of the button and that should work 😉😊
@PhillyWebRadio
@PhillyWebRadio Жыл бұрын
operating_system = sys.platform NameError: name 'sys' is not defined
@FabioMusanni
@FabioMusanni Жыл бұрын
Are you sure you watched the whole video? 😊 Hint: you probably skipped something at the beginning 😉
@rutenowynidoking3593
@rutenowynidoking3593 Жыл бұрын
its not working in PyCharm 😕
@FabioMusanni
@FabioMusanni Жыл бұрын
I've researched a bit and it seems that certain OS commands don't work in PyCharm because it's an IDE. This definitely works in the terminal, which is the most important thing, since people run programs from the terminal. If you want it to work in PyCharm as well you should enable one thing: Run --> Edit Configurations --> In the Popup, under execution, you need to enable "Emulate terminal in output console" After this everything should work in PyCharm too. 😉
@divanshubakshi4394
@divanshubakshi4394 11 ай бұрын
@@FabioMusanni Sorry to say but still after this command its still not working in pycharm.
@FabioMusanni
@FabioMusanni 11 ай бұрын
@@divanshubakshi4394 I'm sorry to hear that! Does it work if you run the code in the terminal? If so that's definitely something to do with Pycharm.
@divanshubakshi4394
@divanshubakshi4394 11 ай бұрын
Yes it worked after i replaced clear with 'cls' in command. Thanks for commands and troubleshooting steps though
@FabioMusanni
@FabioMusanni 11 ай бұрын
@@divanshubakshi4394 Perfect! Glad to hear that! 💪 If you are using Windows you need to use 'cls', 'clear' can be used on Linux for example. That's why in the video I do different things depending on the OS.
Python Iterators | How the for Loop Works Under the Hood
8:02
Fabio Musanni - Programming Channel
Рет қаралды 734
How to Overwrite Previous Printed Line in Python | Print Without Newline | Carriage Return
12:14
Fabio Musanni - Programming Channel
Рет қаралды 23 М.
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19
Watermelon magic box! #shorts by Leisi Crazy
00:20
Leisi Crazy
Рет қаралды 81 МЛН
Win This Dodgeball Game or DIE…
00:36
Alan Chikin Chow
Рет қаралды 43 МЛН
Top 18 Most Useful Python Modules
10:50
Tech With Tim
Рет қаралды 931 М.
Full Stack Developers will take over. This is why.
11:26
Ed Andersen
Рет қаралды 56 М.
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
Run Python Scripts With Command Line Arguments Using sys.argv (With Examples)
23:33
Fabio Musanni - Programming Channel
Рет қаралды 10 М.
Access Location, Camera  & Mic of any Device 🌎🎤📍📷
15:48
zSecurity
Рет қаралды 2,4 МЛН
How To Use Functions In Python (Python Tutorial #3)
14:55
CS Dojo
Рет қаралды 2,4 МЛН
Beautiful Terminal Styling in Python With Rich
13:17
Patrick Loeber
Рет қаралды 140 М.
you need to learn Python RIGHT NOW!! // EP 1
17:42
NetworkChuck
Рет қаралды 2,4 МЛН
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19