Easy questions from a python beginner

Carl Banks pavlovevidence at gmail.com
Sun Jul 11 17:03:52 EDT 2010


On Jul 11, 11:45 am, wheres pythonmonks <wherespythonmo... at gmail.com>
wrote:
> On #4:  So there are some hacks, but not something as easy as "import
> unimportable" or an @noexport decorator.  The underscore works, so
> does "del".

Careful.  If you have a module that looks like this:


def foo():
    bar()

def bar():
    print "hello"

del bar # bar is an internal function


It won't work; foo will raise NameError on bar if you try that.
However, del is useful to clean up code you run at module import time,
for example:


squares = []
for i in xrange(101):
    squares.append(i*i)
del i


Carl Banks



More information about the Python-list mailing list