Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nope, it's more complicated than that:

    e = 'before'
    try:
        x = int('cat')
    except Exception as e:
        e2 = e
        print(e)
    print(e2) # <- This works!
    print(e)  # <- NameError: name 'e' is not defined
It's not a scoping thing, the bound exception variable is actually deleted after the exception block, even if it was already bound before!


lol - raku maybe weird, but at least it has sane variable scoping




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: