Is it possible that Camera.set_controls() doesn't work in pygame?
I am on Version 1.9.x and try it on my RasPi, but it always crashes.
It says there are no keyword arguments - But if I don't use keywords, it crashes with another message (I don't have the message in my mind at moment)
Errors:
This was sent via PuTTy, but it doesn't work if I directly use it on the RasPi, too.
The error message is see unambiguously:
set_controls() takes no keyword argument
So you can't write camera.set_controls(hflip = True, vflip = True), but you have to write
camera.set_controls(True, True)
Note set_controls is implmented using CPython. Also see GitHub - Pygame - _camera.c
Related
I am trying to call a method with no input arguements which is as follows :
[1]
[1]: https://i.stack.imgur.com/tGFe9.png
So far I have tried this :
method=client.get_node("ns=5;s=Demo.StateMachines.Program01.Reset")
parent=client.get_node("ns=5;s=Demo.StateMachines.Program01")
output=parent.call_method(method)
but it given me this BadNotExecutable error:
"The executable attribute does not allow the execution of the method."(BadNotExecutable)
The server is telling you this method cannot be executed.
There doesn't appear to be anything wrong with your client, check the server configuration.
I have a bit of trouble using a callback as an argument to a function. I am using a python package called keyboard which has a function called keyboard.add_word_listener() with required arguments of text and callback. The text is simply the word the function is looking for, and according to the docs, the callback is "is an argument-less function to be invoked each time the given word is typed." I have been passing a function through that argument that is essentially just printing things. To the best of my knowledge, this should run all of the code within the function whenever it detects the text is typed. However, it immediately runs the function, before I type anything, and when I actually do type the text, it gives the error 'NoneType' object is not callable. If anyone could tell me why this isn't working the way it should, that would be great. Minimum reproducible example:
import keyboard
stopKey = "Windows"
def test():
print("Success!")
keyboard.add_word_listener("test", test())
running = True
while running:
if keyboard.is_pressed(stopKey):
running = False
As you can see, when you run the program, it immediately prints "Success!" and if you type "test" + space anywhere, it gives an error message.
dos not use parenthesis to pass the fucntion, you are "calling" it
keyboard.add_word_listener("test", test) # no parenths
I am currently testing a Click CLI application and get result.exit_code == 2. Why does that happen?
This appears to indicate a usage error:
An internal exception that signals a usage error. This typically aborts any further handling.
This is consistent with Click's own tests, e.g.
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L82
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L190
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_arguments.py#L201
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L157
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L177
https://github.com/pallets/click/blob/123dd717439d8620d8d6be5574d2c9f007952326/tests/test_formatting.py#L193
I ran
result = runner.invoke(cli, ['sync'])
instead of
result = runner.invoke(cli, ['--debug', 'sync'])
So you need to specify the flag as entered via CLI, not only pass the parameters consumed by the function if you use #click.option.
Additionally, the I made a typo for one of the flags.
How to debug
Look at the parameters you pass to runner.invoke (simplest: print it)
Execute it via CLI (e.g. cli(['--debug', 'sync']))
In my case this gave me the message
Error: no such option: --sync Did you mean --syncs?
This is my best attempt at a multienterbox with Easygui and Python.
Would someone please give me a working example?
import easgui
(fieldNames= ['Year','Month','Day','Time Hour','Time Minute', 'AM or PM'])
log = easygui.multenterbox(msg='Fill in the blanks',title='log', fieldNames)
I am running Python 2.5 on OS X 10.6
There are parentheses around your first line - this isn't allowed.
You've haven't used the keyword syntax for your third argument, but you use if for the first two.
Either
log = easygui.multenterbox(msg='Fill in the blanks',title='log', fieldnames=fieldNames)
or
log = easygui.multenterbox('Fill in the blanks', 'log', fieldNames)
would work.
It looks like it'd be useful for you to try typing these commands in an interpreter (open a terminal (search for "Terminal" with spotlight) then type the lines one by one, and look for error you get, or in a terminal type "python yourscript.py" so you can see the error messages. Each of these problems has a helpful error message describing the problem, once you get used to reading these you can debug your own scripts.
I'm trying to save myself just a few keystrokes for a command I type fairly regularly in Python.
In my python startup script, I define a function called load which is similar to import, but adds some functionality. It takes a single string:
def load(s):
# Do some stuff
return something
In order to call this function I have to type
>>> load('something')
I would rather be able to simply type:
>>> load something
I am running Python with readline support, so I know there exists some programmability there, but I don't know if this sort of thing is possible using it.
I attempted to get around this by using the InteractivConsole and creating an instance of it in my startup file, like so:
import code, re, traceback
class LoadingInteractiveConsole(code.InteractiveConsole):
def raw_input(self, prompt = ""):
s = raw_input(prompt)
match = re.match('^load\s+(.+)', s)
if match:
module = match.group(1)
try:
load(module)
print "Loaded " + module
except ImportError:
traceback.print_exc()
return ''
else:
return s
console = LoadingInteractiveConsole()
console.interact("")
This works with the caveat that I have to hit Ctrl-D twice to exit the python interpreter: once to get out of my custom console, once to get out of the real one.
Is there a way to do this without writing a custom C program and embedding the interpreter into it?
Edit
Out of channel, I had the suggestion of appending this to the end of my startup file:
import sys
sys.exit()
It works well enough, but I'm still interested in alternative solutions.
You could try ipython - which gives a python shell which does allow many things including automatic parentheses which gives you the function call as you requested.
I think you want the cmd module.
See a tutorial here:
http://wiki.python.org/moin/CmdModule
Hate to answer my own question, but there hasn't been an answer that works for all the versions of Python I use. Aside from the solution I posted in my question edit (which is what I'm now using), here's another:
Edit .bashrc to contain the following lines:
alias python3='python3 ~/py/shellreplace.py'
alias python='python ~/py/shellreplace.py'
alias python27='python27 ~/py/shellreplace.py'
Then simply move all of the LoadingInteractiveConsole code into the file ~/py/shellreplace.py Once the script finishes executing, python will cease executing, and the improved interactive session will be seamless.