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.


    Button titles with numbers have invalid syntax?

    Pythonista
    4
    7
    1726
    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.
    • RocketBlaster05
      RocketBlaster05 last edited by RocketBlaster05

      I was calling on a button starting with a number, and the number gets coded as red and when I run the app it says “invalid syntax” on the 8 shown below. Is there a work around for this? Thanks.

      def wb8(8oz./0.237L): 
             #^invalid syntax
      
      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @RocketBlaster05 last edited by

        @RocketBlaster05 Python variables names have to begin with alphabetic.
        If you wb8 is the action of a button, use def wb8(sender):
        Usually, we don't set as parameter the title of the button.

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

          You also cannot use periods or slashes in the name of a variable/identifier.

          As cvp said, identifiers must start with an alphabet character, then contain only a-z and 0-9, or underscore Also, no special characters, no reserved keywords, no operators.

          I wonder if you meant to pass in a string default value or something, but that's not how button actions work.
          https://www.askpython.com/python/python-identifiers-rules-best-practices

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

            @JonB, in these modern times we can use all unicode alphabetic characters in variables, so I could have e.g. päiviä (days) as a variable name.

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @mikael last edited by

              @mikael said:

              modern times

              Yes, but does Pythonista support modern fashion?

              1 Reply Last reply Reply Quote 0
              • cvp
                cvp @RocketBlaster05 last edited by cvp

                @RocketBlaster05 anyway, don't use the name or title of your buttons as parameter for their action, use the standard way of naming it "sender"

                def action_of_your_button(sender):
                

                in this case you can always get the button name or title via

                  print(sender.name)
                  print(sender.title)
                

                That could seem strange for you, but assume two buttons have the same action...

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

                  Thanks for all the replies. I decided to just use sender. I didn't realise how easy it is to just write sender for the buttons lol. Thanks for the suggestions everyone!

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