Proposal: Inline Import

adam adam_goucher at
Mon Dec 12 21:38:35 CET 2005

When I'm feeling too lazy to do imports while moving large blocks of
code, I use this little hack. It lets me proceed with checking whether
the move does what I wanted and at the end I fix the imports and remove
the try/except wrapper. I think it would achieve your desired result
and not have an impact on the language itself.

    #your main code here
    print string.upper("blah")
except NameError, error_value:
    mod_name = error_value.args[0][error_value.args[0].find("'") +
        print "imported %s" % mod_name
        print "NameError: %s" % error_value.args[0]


More information about the Python-list mailing list