Python AttributeError: module 'os' has no attribute 'exit'

I'm using Python 3.9.12 and I get error in the following line

os.exit()

the Error message is: AttributeError: module 'os' has no attribute 'exit'

Upvotes: 1

Views: 3620

Answers (3)

As from comment, exit is a built-in. So os.exit() becomes exit()

Upvotes: 1

Z.wk
Z.wk

Reputation: 49

make sure variable os not been overwrited, like filename or varable name ...

Upvotes: 1

LinFelix
LinFelix

Reputation: 1072

os.exit() is not and was not a method of the os module. You may confuse it with os._exit() or sys.exit()

Upvotes: 3

Related Questions