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.


    Importing between files

    Pythonista
    3
    5
    3216
    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.
    • vignesh
      vignesh last edited by

      On pythonista, how do I share information between python files. If I had a file called 'main.py' and then another called 'extension.py' and there are functions I want from extension.py in main.py, I would use 'import extension'. I do this and it calls an error that states that 'there is no module extension'

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

        It is easy, put the extension.py and the main.py file in a folder with a file called __init__.py, them in the main.py

        import extension
        extension.your_function()
        

        I hope this work for you

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

          You can see this for more help

          Documentation

          vignesh 1 Reply Last reply Reply Quote 0
          • vignesh
            vignesh @sulcud last edited by

            @sulcud Thanks so much!

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

              The __init__is only necessary if you want to import by folder name. The key is that, if you run main.py, extension.py must be in the same folder, or otherwise on sys.path (for instance, in site-packages).

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