Search code examples
pythonlinuxterminalenterpycassa

Can you use python to type text and press enter in command prompt?


I made a little python function, which I would then like to use in a Linux command prompt. However, in order for it to run correctly in the command prompt, I need to first type "pycassaShell" into the command prompt so that pycassaShell is running before I input any further commands. Thus, is there any way to do this in my python program itself?

For example, I would like the python code to do the following:

  • Open command prompt
  • Enter "pycassaShell"
  • Press enter key
  • Run the function I created in the python program.

Alternatively, is it possible to simply access a function written in a python file directly in pycassaShell?

I apologize if this is a bad question, but I am new to using command prompt in general. Thanks!


Solution

  • pycassa is a Python module with a full-fledged API. Instead of trying to operate inside of its shell from within Python, you should import the module and use it directly.

    Documentation about the API can be found here:

    http://pycassa.github.io/pycassa/api/index.html

    In contrast, pycassaShell is the interactive shell wrapper around pycassa meant for manual exploration (as opposed to programmatic execution).

    http://pycassa.github.io/pycassa/assorted/pycassa_shell.html

    So, I would recommend that you adapt your function to use the imported pycassa module directly as opposed to the pycassaShell shell. Then you can use that new function freely within your Python script.