1

This is simple Python code on Windows. The problem is when I hit Ctrl + C, some of the code will be displayed on the screen even though I have already converted .py to .exe using pyinstaller

Code

C:\code>more test.py
#!/usr/bin/python

print("\n Hello")
input(" Pause ... ")

C:\code>

Normal execution

C:\code>python test.py

 Hello
 Pause ...

C:\code>

Ctrl + C during execution ... before code paused

C:\code>python test.py

 Hello
 Pause ... Traceback (most recent call last):
  File "test.py", line 4, in <module>
    input(" Pause ... ")
KeyboardInterrupt

C:\code>

Would it be possible to hide this code even someone hit Ctrl + C during code execution?

1 Answers1

4

Just wrap the code in a try-except statement

try:
    print("\n Hello")
    input(" Pause ... ")
except KeyboardInterrupt as ki:
    pass
dangee1705
  • 3,445
  • 1
  • 21
  • 40