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

    Appending data on an SD card file

    Scheduled Pinned Locked Moved Discussion
    sipypymakrsd cardpycom
    5 Posts 3 Posters 1.8k Views 3 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.
    • J Offline
      Josh
      last edited by

      Hi All,

      I am trying to create a simple data-logger using some very simple sensor inputs as a test. I am using the “SD” and “os” modules to write values to a text file on an SD card on the pymakr board. I can mount it and then open the file to successfully write to the card, however, when I close and then re-open the file when I want to write to again it overwrites my original data.

      Is there any way to append the data in the file instead of overwriting?

      I can't to keep the file open as I might want to turn the logger off and on over different sessions. I also don’t want to “readall()” my existing data into RAM, append, then re-write the entire data-set as this is ugly, slow and I might have a large amount of data which could crash the system.

      Seems like pretty standard functionality to miss out, if this is the case.

      I also noticed that there is not a delete file function mentioned in the “os” module which is what the “SD” example code uses, but there is a similar module called “uos” in which you can. Does anyone know why there are two similar “uos” and “os” modules despite being somewhat redundant and why “os” is not in the documentation?

      Can anyone clarify this for me please?

      Thanks in advance.

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @Josh
        last edited by

        @josh you just have to open the file in append mode:

        f = open("the_file", "a")

        1 Reply Last reply Reply Quote 1
        • J Offline
          Josh
          last edited by

          Ah excellent, that's an easy solution!

          Thanks again Robert :)

          1 Reply Last reply Reply Quote 0
          • sebS Offline
            seb
            last edited by

            Hi,

            uos is the micropython version of the os library. When you do import os, it is actually just an alias and it really imports uos. This is for compatibility with existing python code. If you go to the REPL on your device and run

            import uos
            dir(uos)
            import os
            dir(os)

            You will see the lists are identical. If we are missing documentation for some of the methods I will add it to my to-do list to add this documentation.

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              Josh @seb
              last edited by

              Hi @seb

              Thanks that clears things up a lot!

              I didn't know I could list the methods in each module either, useful to know...

              That would be fantastic if you could add this sort of extra detail in the documentation, I'm sure that will save me a lot of time!

              Thanks again.

              1 Reply Last reply Reply Quote 0

              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