Shuman
Shuman

Reputation: 4132

How to quit python interpreter with code?

I want to quit interpreter when -i is passed in. eg

> python -i test.py
yeah
SystemExit
>>>

I want to quit interpreter. my test.py

import sys
print 'yeah'
sys.tracebacklimit = 0
sys.exit()

I have tried exit() and quit(), but I am still in the interpreter. The reason I want to do this is because I have a script from mayapy( autodesk maya python interpreter ), which launches like this mayapy -i myscript.py [args], I want to quit interpreter when --help is passed as argument, but it always stays in interpreter because -i is passed in.

Is there a way to have the same effect as ctrl+d ?

Upvotes: 0

Views: 348

Answers (1)

deets
deets

Reputation: 6395

You can invoke the os._exit call.

import os
os._exit(0)

Upvotes: 2

Related Questions