python refresh/reload

后端 未结 7 1022
北海茫月
北海茫月 2020-11-27 17:58

This is a very basic question - but I haven\'t been able to find an answer by searching online.

I am using python to control ArcGIS, and I have a simple python scrip

7条回答
  •  借酒劲吻你
    2020-11-27 18:44

    I'm not really sure that is what you mean, so don't hesitate to correct me. You are importing a module - let's call it mymodule.py - in your program, but when you change its contents, you don't see the difference?

    Python will not look for changes in mymodule.py each time it is used, it will load it a first time, compile it to bytecode and keep it internally. It will normally also save the compiled bytecode (mymodule.pyc). The next time you will start your program, it will check if mymodule.py is more recent than mymodule.pyc, and recompile it if necessary.

    If you need to, you can reload the module explicitly:

    import mymodule
    
    [... some code ...]
    
    if userAskedForRefresh:
        reload(mymodule)
    

    Of course, it is more complicated than that and you may have side-effects depending on what you do with your program regarding the other module, for example if variables depends on classes defined in mymodule.

    Alternatively, you could use the execfile function (or exec(), eval(), compile())

提交回复
热议问题