Skip to content

Eliminate dependency on sys module in "if main" snippet#429

Merged
DonJayamanne merged 1 commit into
DonJayamanne:masterfrom
gandhis1:master
Oct 25, 2016
Merged

Eliminate dependency on sys module in "if main" snippet#429
DonJayamanne merged 1 commit into
DonJayamanne:masterfrom
gandhis1:master

Conversation

@gandhis1

@gandhis1 gandhis1 commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

Justification:

  • Putting an import within the "if main" seems unconventional, most linters will ask you to move it to the top of the module, typically leads to one manually copying the import to the top of the module - it is no longer a self-contained snippet
  • It doesn't seem that common of a convention for instance here in the official Python docs, or here from a popular question on StackOverflow
  • There is a very old blog post by Guido about this, which is similar to the current implementation, but is attempting to remedy what probably is a non-issue - one calling sys.exit() in the main() function
  • For simplicity purposes, and cleanest code, I think the sys module dependency and associated exit() call should be removed

@DonJayamanne DonJayamanne merged commit dc98883 into DonJayamanne:master Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants