Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Oh, there is in fact some magic behind that. Python treats "assert" as a special case; in Optimize mode (-O or -OO), the Python compiler completely removes the assert and its expression from the resulting bytecode.
- So, we sometimes use this magic to optimize statements that we only want in the development environment, but not in the production environment. Usually, it would only be done on a "debug" type notify, which will be turned off in production anyway. So:
- self.notify.debug("Here's some debug output")
- and:
- assert self.notify.debug("Here's some debug output")
- Would both produce exactly the same result in a normal production environment (no output at all), but the former will result in a runtime test of the current state of self.notify.__debug, while the latter will result in no code at all.
- As far as I know, assert is the *only* Python function with special compile-out magic built in like this.
Add Comment
Please, Sign In to add comment