[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Equivalent to __name__ == “_main__”?
- From: Paul Ducklin <pducklin@...>
- Date: Sun, 5 Dec 2021 12:01:28 +0000
Excuse my ignorance, but is there a “official” (read: preferred/reliable) way to detect that you have run a module directly as a program instead of loading it with require()?
Like the “name == main” trick in Python?
I have seen suggestions to use debug.getinfo() to probe the call stack depth, and testing whether the stack is too shallow to be inside a call to require(). Does that work? Is there a better way?