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.


    Modules working ?

    Pythonista
    3
    4
    2736
    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.
    • momorprods
      momorprods last edited by

      Hey, so again I feel a bit dumb asking a so-basic question, but I wasn't able to have basic modules working:

      File 'a.py':

      aa = 'Test'
      

      File 'b.py':

      import a
      print(a.aa)
      

      Running b.py throws the following error : **AttributeError : 'module' object has no attribute 'aa' **

      Any clue about what is going on ?

      Thanks !

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

        The import statement caches modules, meaning that if you import a more than once (even across different scripts) it will only be loaded once. Because Pythonista runs only a single Python process, this means that if you import a, modify a.py and then import a again, the changes to a won't be visible right away. In the interactive prompt, run import a, then reload(a) to reload the module from a.py, and then run your b.py again and see if it works.

        If that didn't help, see if there are any other files named a.py that might be imported instead of the one you want. Pythonista doesn't come with any module named a by default, but if you have a file a.py in your Script Library or site-packages, that might be imported wrongly. If you want to find out where the module a was imported from, see a.__file__.

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

          It works as expected for me. Try adding reload(a) line just after the import line. Also, make sure the filename is all lowercase.

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

            Thanks guys, the reload() trick did it !

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