| | |
Clearing the screen of text
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#11 Oct 20th, 2009
•
•
•
•
Can anyone kindly explain the background of how this bit of code works?python Syntax (Toggle Plain Text)
import os # works on windows nt (also xp and vista) or linux os.system(['<strong class="highlight">clear</strong>','cls'][os.name == 'nt'])
python Syntax (Toggle Plain Text)
import os # works on windows nt (also xp and vista) or linux os.system(['clear','cls'][os.name == 'nt'])
['clear','cls'][1] is 'cls', which is passed to os.system. On another system, 'clear' is passed.This is old style coding. Nowadays, one writes
python Syntax (Toggle Plain Text)
os.system('cls' if os.name == 'nt' else 'clear')
0
#13 Oct 20th, 2009
python Syntax (Toggle Plain Text)
import os # works on windows nt (also xp and vista) or linux os.system(['clear','cls'][os.name == 'nt'])
Should you find Irony, you can keep her!
![]() |
Other Threads in the Python Forum
- Previous Thread: Problems writing code for my project
- Next Thread: Letter frequency function using lists
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion recursive schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere webservice wikipedia windows wxpython xlib






