-1

I was working with this KDE widget and was having hard time trying to access it with python, I figured out with some help that I was trying to do it right originally and if I patch the 2 files below in the widget to change the name from pass to say pypass or just add a copy of this pass feature under a new name I can use the new name no problem, is this a false positive in the syntax check or just a usage issue? is there a way to work around this issue?

These give a syntax error cause of the word pass

#!/bin/python3
from pydbus import SessionBus
diy=SessionBus().get("org.kde.plasma.doityourselfbar","/id_10")
diy.pass('|A|Label|Tooltip|notify-send hello world|')
#!/bin/python3
from dbus import SessionBus
diy=SessionBus().get_object("org.kde.plasma.doityourselfbar","/id_10")
diy.pass('|A|Label|Tooltip|notify-send hello world|')

I did try to set it like this but I just get a Key Error, so much for it behaving like JavaScript...

  • diy['pass]('string')
ukBaz
  • 6,985
  • 2
  • 8
  • 31
  • 2
    Perhaps it is because `pass` is a reserved word in python: https://docs.python.org/3/reference/lexical_analysis.html#keywords. – j1-lee Nov 24 '21 at 05:12
  • 2
    Here's a lifelong tip you can apply over and over: if you're new to a programming language, and it's not behaving the exact way you expect: chances are quite likely it's not "a bug in the language". – mechanical_meat Nov 24 '21 at 05:19
  • Use `pass_` instead. this is a common idiom for (other) reserved words like `raise`. – rv.kvetch Nov 24 '21 at 05:27

1 Answers1

4

No, it's not "a bug in the language", you just can't do that, because pass is a language keyword. I don't know if pydbus provides a nice way for calling a method by name, bypassing its proxies, but if it doesn't, you should be able to do

getattr(diy, 'pass')('string')
hobbs
  • 223,387
  • 19
  • 210
  • 288