I don't have any of my own examples I can provide, but are you familiar with the subprocess module in Python? It sounds like that may be what you want. You can spawn a new process from Python 2.7 code (to run your Python 3 script) and set it up such that the stdin and stdout can be read and written to.
This is the Python 2.7 documentation for the subprocess module:
https://docs.python.org/2.7/library/subprocess.htmlAnd I think this site has a great writeup with some examples on using the module. It covers writing to and reading from stdin and stdout of a subprocess:
https://lyceum-allotments.github.io/2017/03/python-and-pipes-part-5-subprocesses-and-pipes/Here is a snippet taken from one of the examples where you can write to the stdin of the spawned process (you can do something similar for reading from stdout as well):
- Code: Select all
proc = subprocess.Popen(["python", "say_my_name.py"], stdin=subprocess.PIPE)
proc.stdin.write("matthew\n")
proc.stdin.write("mark\n")
proc.stdin.write("luke\n")
Maybe this will point you in the right direction or at least make you aware of the subprocess module if you haven't heard of it. Good luck!