omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Scripts not updating on import?

    Editorial
    3
    7
    4771
    Loading More Posts
    • 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.
    • mwerevu
      mwerevu last edited by

      I discovered this in a more complex set of code, but I've boiled the issue down to two very simple scripts:

      mainprog.py

      from helper import  helpfunc
      print helpfunc(6)
      

      and

      helper.py

      def helpfunc(val):
          return 2*val
      

      All goes fine the first time I run mainprog.py and the output is 12, but if I change the "2" to a "3" in the helper.py script, then when I run the mainprog.py script, the output is still 12.

      The only way I can get mainprog.py to pick up the changes in helper.py is to force quit pythonista.

      Am I missing something?

      1 Reply Last reply Reply Quote 0
      • Stefano
        Stefano last edited by

        Try reload( helpfunc ) at the end of mainprog.py, it should do the math.

        1 Reply Last reply Reply Quote 0
        • mwerevu
          mwerevu last edited by

          Got a TypeError when I tried that. reload wanted a module.

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            Try adding import helper; reload(helper) before the from-import.

            1 Reply Last reply Reply Quote 0
            • Stefano
              Stefano last edited by

              Right, reload works with module objects — successfully imported before — only …

              1 Reply Last reply Reply Quote 0
              • mwerevu
                mwerevu last edited by

                Yup. That worked. Thanks!

                I'm not a python expert, but is this something unique to pythonista? I've not encountered this before in other IDEs.

                1 Reply Last reply Reply Quote 0
                • omz
                  omz last edited by

                  It's kind of unique to Pythonista – IDEs on other platforms usually run scripts in a separate process, this is technically impossible to do on iOS (at least in an App Store app), so Pythonista runs a single interpreter and imports are cached (which is just how Python works, it's the same on any platform when you use the command-line Python).

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors