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?
-
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
-
@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. -
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 -
@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. -
-
@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...
-
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!