Python3 - reload() can not be called on __import__ object?

44,860

The reload built-in function has been moved to importlib module in Python 3.4:

In [18]: from importlib import reload

In [19]: reload?
Reload the module and return it.

The module must have been successfully imported before.

As pointed out by @JPaget in comments reload() function has been moved from imp to importlib module in Python 3.4+. From what's new in Python 3.4:

The reload() function has been moved from imp to importlib as part of the imp module deprecation

Share:
44,860
Torxed
Author by

Torxed

Not much to say to be honest, Alongside everyone here i'm "ish" a beginner in Python/C/C++/ASM but i enjoy what i do and i do it for fun which i think is a key factor to keep on doing the things i like. I'm probably a duct tape developer by hobby, I make stuff work - fast. It's not always the most pretty thing in the world, but it'll do the job.

Updated on May 25, 2020

Comments

  • Torxed
    Torxed almost 4 years

    Ok so for a number of reasons, I've been using s = __import__('parse') for the longest time in Python2, now I sorta need to being my transitions to Python3 for certain projects (mainly due to SSL).

    But there's no reload() equivilant in Python3 as far as i've spotted. There's only one option:

    import parse
    parse.reload() #works
    

    But I really, really need this to work:

    parse = __import__('parse')
    parse.reload()
    

    or

    reload(parse)
    

    Any ideas on how to get it working in Python3?

  • Roeland
    Roeland over 9 years
    As of Python 3.4, imp is deprecated. Use importlib instead: from importlib import reload