6 Replies - 2025 Views - Last Post: 16 March 2013 - 12:09 PM Rate Topic: -----

#1 BackSlashx00  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 24-February 13

Is system('cls') bad practice?

Posted 15 March 2013 - 11:45 PM

I am working with Python right now, and I would like to know if using
os.system('cls')
is practice, and if so what are other ways to create a clear function? I know in C++
system("CLS");
is bad practice so I usually create my own functions for clearing, and pausing. I am not sure if os.system('pause > nul') is bad practice in python either? Any advice, and help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Is system('cls') bad practice?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3354
  • View blog
  • Posts: 11,360
  • Joined: 12-December 12

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 01:28 AM

IMO it doesn't matter. These are commands that we use when learning Python, and testing programs in console (terminal) windows. Production code would generally create either a Desktop or Web-based application, for which these commands wouldn't be necessary.

Console applications are sometimes created, for systems programmers to use. They probably won't care if you clear the screen or pause, as long as the application works :)
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,204
  • Joined: 21-June 11

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 02:24 AM

Well, the application won't work on non-Windows systems if you invoke cls. Well, I suppose it will work, but with an annoying error message appearing every time you try to clear the screen. And that's definitely annoying.

Also note that clearing the screen will make it harder to use the application from inside shell scripts or other applications. The same is true for waiting for a keypress before closing the application. So you should definitely not do these things in production code.
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5800
  • View blog
  • Posts: 12,636
  • Joined: 16-October 07

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 05:15 AM

Yes... YES, it's a bloody awful practice. Same with the pause.

For the pause, you can just use a python input. For a clear screen... why the hell do you want to clear the screen, anyway?

Ok, for your own amusment, it's fine. But it's a habit you shouldn't be in.

The issue is that the minute you call system, in any language, you've given up control and are praying to the OS gods to make it work. This should make any programmer cringe. If you run your program as admin, all an evil hacker script kiddie need do is put a cls.bat in your path with some fun command like "format c:"
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,204
  • Joined: 21-June 11

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 05:34 AM

View Postbaavgai, on 16 March 2013 - 01:15 PM, said:

For the pause, you can just use a python input.


Which is better than pause in a lot of ways, but still has the disadvantage that it makes it harder to use in a script. Plus I find it annoying if I have to press a key before I'm back at the command prompt - but that's a matter of personal preference, I suppose.

Quote

If you run your program as admin, all an evil hacker script kiddie need do is put a cls.bat in your path with some fun command like "format c:"


Wouldn't any script kiddie who gained enough access to be able to put stuff in my PATH also have enough access to just execute format c: directly?

This post has been edited by sepp2k: 16 March 2013 - 05:35 AM

Was This Post Helpful? 0
  • +
  • -

#6 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5800
  • View blog
  • Posts: 12,636
  • Joined: 16-October 07

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 06:14 AM

Agreed, pause sucks. But, if you're going to do it in python, or any language, make it a function. That way, when I use your code, I can just comment it out in one place.

View Postsepp2k, on 16 March 2013 - 07:34 AM, said:

Wouldn't any script kiddie who gained enough access to be able to put stuff in my PATH also have enough access to just execute format c: directly?


Ah, but it's so much better when the unsuspecting victim shoots their own foot off... :P

Windowy world is a little wierd; users are generally admins and there your are. Still, if I was just a humble user ( and windows can have them ), and I could sneak my little bit of evil into YOUR path, and you execute a "safe" program that has to ask for admin rights anyway. Well, gotcha.

In *nix this kind of hack used to be more common, because programs could have sticky bits set that would change user context, often to root. Sneak something into that and you're running as root. While sticky bits still exist, they're far less common. However, anything that runs as a service, or is run by a service, is a possible hole. Hint, never let your web server run as root.
Was This Post Helpful? 0
  • +
  • -

#7 BackSlashx00  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 24-February 13

Re: Is system('cls') bad practice?

Posted 16 March 2013 - 12:09 PM

The reason why I asked about the os.system('cls') because I was using it in a console prompt instead of the python shell. But I understand your point of views for not using it in production unless I am by myself and no one is looking lol.

I would only use it for testing purposes*
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1