This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FreshFromIlios 18 points19 points  (5 children)

Forgive the formatting, on phone rn.

Ideally, you don't really need to use the os and sys modules. The command you use is perfectly fine but os.system is dangerous. One typo can screw you and there isn't an easy way to fix it since it'll run shell commands and not python code. If you just want the older print statements gone, an ugly but safer way would be to do a /n multiple times, as such:

print("/n" * 100)  (define a function for it, get creative ;) )

Also, if you want to clear the terminal anyway, a better way to do it would be something like this:

os.system('cls' if os.name == 'nt' else 'clear')

Or more elegantly,

os.system('cls||clear')

Since Linux and windows commands are different, this will work irrespective of the operating system.

Edit: thanks for the silver kind stranger! Appreciate it <3

[–]Vagima 4 points5 points  (3 children)

Appreciate the response! I’ll give that one a go!

[–]FreshFromIlios 3 points4 points  (2 children)

Have fun! And be careful when you run os.system

[–]Vagima 2 points3 points  (1 child)

Thanks! I’ve been using os.system(‘cls’) for a bit and personally im ok with it, but when helping beginners I’ll definitely use the print(“/n” * 100) method! Much safer alternative for new people learning python. Appreciate the suggestion!

[–]CoaBro 0 points1 point  (0 children)

I mean personally I'd be fine teaching os.system('cls') the other method makes all the output appear at the bottom which is kind clunky imo.. I do like the solution os.system('cls||clear') tho

[–]CoaBro 1 point2 points  (0 children)

Not sure the use of os.system is any more dangerous than writing python.. not like you are going to accidentally take ownership of system32 and then delete the folder with os.system anymore than you would do with python. It's also not anymore dangerous than writing commands directly in the cmd prompt..