New on Dynamically Typed this morning, there's a posting concerning a Python feature many find very useful.
One of those nice features of Python, that marks it as a language designed for developers (as opposed to one designed for tool vendors) is the ability to conditionally run some logic if you're executing a script directly but ignore it if the script is being imported ("included") by another script.
Using a statement such as "'if __name__ == "__main__":" only allows a block of code to be executed when it's run directly. Of course, the same kind of thing can be accomplished with PHP, just in a few more lines. Using the __FILE__ predefined constant. Using this results in several calls to the constant, making for a bit more overhead, so his recommendation is to assign the __FILE__ value to another user-defined constant, making the value held in memory for faster access.




