Check for if __name__ == "__main__":
#3730
steve-mavens
started this conversation in
Ideas
Replies: 1 comment
-
Note that a lot of Windows programs create files executable by default, especially IDEs that "know" that all .py files are scripts. So depending on your view of this, the rule is either highly useful to clear that up on files not intended to be executed as scripts, or wrong because it violates a Windows convention that everything's an executable script until proven otherwise. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is similar in intent to EXE001 and EXE002, which compare the file executable permissions against whether or not there is a
#!
at the start of the file.If my Python file has executable permissions, then it must have an
if __name__ == "__main__":
it in somewhere. My reasoning is that in anything other than ad hoc scripts, I always want it to do something different when imported as a non-main module for testing or documentation, from what it does when run.I think the implication back in the other direction is weaker than for shebangs. There could very well be files which have the
if __name__ == "__main__"
but do not have the executable bit set or the shebang, because they're intended to be run withpython -m
. I think it's useful to be able to lint that there are no such files, though.Beta Was this translation helpful? Give feedback.
All reactions