0

How can I call textinput.py from another python file? I would like to call it and send a text query as an argument rather than getting the input from the user. Thank you

Ran
  • 57
  • 6
  • This may help: https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path – Nick Felker Feb 23 '21 at 18:06
  • `code` `import importlib.util spec = importlib.util.spec_from_file_location("textinput", "/home/pi/assistant-sdk-python/google-assistant-sdk/googlesamples/assistant/grpc/textinput.py") foo = importlib.util.module_from_spec(spec) spec.loader.exec_module(foo) foo.MyClass()` ... I'm getting errorrs when using the above code. @NickFelker – Ran Feb 24 '21 at 09:52
  • I 've used this methods and it is working. I hope it is the correct way . 'code' 'import os os.system('/home/pi/env/bin/python3 textinput.py --query \'XXXX\' --device-id XXX --device-model-id XXXXXX')' – Ran Feb 24 '21 at 13:26
  • I'm glad that it's working for you – Nick Felker Feb 24 '21 at 17:42
  • @Nick, Hi Nick, when running the above code (os.system('/home/pi/env/bin/python3 textinput.py --query \'XXXX\' --device-id XXX --device-model-id XXXXXX')' I'm getting Permission denied. Do have any idea why ? – Ran Feb 07 '22 at 10:44
  • I'm not sure why exactly, but i'm assuming there's an access error for one of the files. – Nick Felker Feb 07 '22 at 17:32
  • When trying to run it from the terminal I get (bash: googlesamples-assistant-textinput: command not found) although pushtotalk works fine. @Nick – Ran Feb 08 '22 at 10:05

1 Answers1

0

I 've used this method and it is working. I hope it is the correct way. import os os.system('/home/pi/env/bin/python3 textinput.py --query \'XXXX\' --device-id XXX --device-model-id XXXXXX')

Ran
  • 57
  • 6