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

    variables starting with underscore

    Scheduled Pinned Locked Moved MicroPython
    2 Posts 2 Posters 149 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.
    • B Offline
      brauliob
      last edited by

      Why is it that in the REPL, the following works

      >>> c = const(10)
      >>> c
      10
      

      but the following does not work

      >>> _c = const(10)
      >>> _c
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      NameError: name '_c' is not defined
      

      ? However, this works when make a script and execute it with a print(_c) statement. It will indeed print 10.

      1 Reply Last reply Reply Quote 0
      • C Offline
        crumble
        last edited by

        MIcropython works a little different than python.

        In python you use the underscrore in front of variable to mark the variable as private. Nut it is still visible. In micropython these are real local variables an will not be exported. So a class will have a memory footprint which is slightly lower.

        The micropython page had this info once under the optimization part. I cannot find it right now. Maybe you have to play around with the version settings in the documentation.

        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