Passing Values From One Python Program To Another
Is it possible -- other than by using something like a .txt/dummy file -- to pass a value from one program to another? I have a program that uses a .txt file to pass a starting v
Solution 1:
This can be implemented using a simple client/server topology using the multiprocessing library. Using your mother/child terminology:
server.py
from multiprocessing.connection import Listener
# clientdefchild(conn):
whileTrue:
msg = conn.recv()
# this just echos the value back, replace with your custom logic
conn.send(msg)
# serverdefmother(address):
serv = Listener(address)
whileTrue:
client = serv.accept()
child(client)
mother(('', 5000))
client.py
from multiprocessing.connection import Client
c = Client(('localhost', 5000))
c.send('hello')
print('Got:', c.recv())
c.send({'a': 123})
print('Got:', c.recv())
Run with
$ python server.py
$ python client.py
Solution 2:
When you talk about using txt to pass information between programs, we first need to know what language you're using. Within my knowledge of Java and Python achi viable despite laborious depensendo the amount of information that wants to work.
In python, you can use the library that comes with it for reading and writing txt and schedule execution, you can use the apscheduler.
Post a Comment for "Passing Values From One Python Program To Another"