syntax for code blocks

Michael Torrie torriem at gmail.com
Thu May 3 00:26:35 EDT 2012


On 05/02/2012 04:52 AM, Kiuhnm wrote:
> The problem is always the same. Those functions are defined at the 
> module level so name clashing and many other problems are possible.

Only functions defined at the module level are in fact in the module's
namespace.  For example, this works fine, and the definitions for one
and two are only within their respective scopes:

def other_part():
    def one():
        pass
    def two():
        pass

    # do something with one and two


def main():
    def one():
        pass
    def two():
        pass

    # do something with one and two

    other_part()

If you are experiencing name clashes you need to start dividing your
code up logically instead of keeping everything in the global namespace
of your module.



More information about the Python-list mailing list