Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Python API
  4. Forcing imported modules to refresh after updating

Forcing imported modules to refresh after updating

Scheduled Pinned Locked Moved Python API
import filepython
2 Posts 2 Posters 656 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jexyll_S
    wrote on last edited by
    #1

    Hi everyone,
    I recently came across a bug which I hadn't previously experienced. I have two scripts, the first is a custom module which is imported into the second script. Normally, I can modify both scripts and when I run them, the modifications are included.

    Today, if I updated the module to be imported and ran the second script, none of the changes would come through. This would only be fixed by closing and reopening sim4life.
    To get around this problem, I had to force my script to reload my imported modules, which can be done in the following way:

    from imp import reload
    import MyModule
    reload(MyModule)
    

    Since I have not come across this problem previously, I am inclined to believe that I have accidentally changed a setting in Sim4Life which is preventing automatic reloading of modified scripts. Any assistance in fixing this would be appreciated, though my current fix should be enough if necessary.

    Cheers,
    Jexyll

    1 Reply Last reply
    0
    • M Offline
      M Offline
      montanaro
      wrote on last edited by
      #2

      This is common. Once you import a script, it becomes cached so even if you make changes to it and save it, python won't see the changes. You need to reload it as you said if you make changes to the imported script after running your main script.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Search