Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How to split project into submodules

    Scheduled Pinned Locked Moved Discussion
    5 Posts 2 Posters 78 Views 2 Watching
    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.
    • mogplus8M Offline
      mogplus8
      last edited by

      Apologies for the noob question. I've missed something but I can't figure out what.

      I'm using VS Code with pymakr plugin (on Linux). I would like to split my project into separate files to make things easier to manage, but I can't figure out how to bring everything together to run the project.

      I have a main.py, which is the main file (surprise) and another file called lookups.py, which has some dictionaries defined in it. I want to refer to the dictionaries from main.py, but I'm not sure how. I've tried every variation of "import" I can think of except for the right one apparently. What do I have to do to refer to another file in the project from the main file?

      All advice gratefully received.

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        @mogplus8 said in How to split project into submodules:

        nt to refer to the dictionaries from main.py, but I'm not sure how. I've tried every variation of "import" I can think of except for the right one apparently. W

        Hi,
        I did it in the following way:

        • Create a folder called lib inside your project
        • In the folder, make a file (eg. thing.py) put your extra functions (do not forget to also copy the necessary imports)
        • use import thing in your main.py file and call the functions like thing.function(), instead you could also do import thing as anothername to use anothername.
          Let me know if that was clear!
          Gijs
        1 Reply Last reply Reply Quote 1
        • mogplus8M Offline
          mogplus8
          last edited by

          Hi @Gijs and thanks for the reply. That combination was one of the first I tried. I assumed that the lib folder was there to contain local libraries, so I put my submodule, "lookups.py", in it. However when I try to run my main.py with "import lookups" in the code I get an error "ImportError: no module named 'lookups'". I get the same error regardless of where I put the module.
          5f00316d-c1eb-4948-af85-efe162841b04-image.png

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gijs
            last edited by

            Ah, I believe the problem is that you have to actually upload to device in order to use it. When you do that, it will upload the main.py, boot.py and /lib/lookups.py to the flash of your device and now they should be callable.

            mogplus8M 1 Reply Last reply Reply Quote 0
            • mogplus8M Offline
              mogplus8 @Gijs
              last edited by

              @Gijs well that did it! thanks!!

              ;-)

              1 Reply Last reply Reply Quote 1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom