How to swallow traceback message

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Aug 11 11:30:01 EDT 2010


Back9 wrote:
> Hi,
>
> I run my py app to display a file's contents, and it is normally very
> long.
> So I use it like below:
>
> python myapp.py input_file | more
> to see them step by step.
>
> But when I try to exit it, normally I use Ctrl+ C key to quit it.
> Problem is every time I do like it, it shows Traceback message and it
> makes my app not professional.
>
> How do I handle it gracefully.
>
> TIA
>   
if __name__ == '__main__':
    try:
       main()
    except KeyboardInterrupt:
       print 'Hey ! this is a professional application'

Cheers,

JM






More information about the Python-list mailing list