简体   繁体   中英

Pass variable between python scripts on different computers.

Im new to programing. I want to know if there is a way to send a variable created on one computer in python to another computer running another python script on the same network. Basically lets say when the Variable is equal to 5 i want the other script to print 5

An easy way to do this would be through web services. Essentially you get ComputerB listening on a port (such as 80, 81, 8100, etc) and have your script on ComputerA talk to it over http.

You can use a simple framework such as web.py or Django hosted in a web server to invoke some Python code that sets this variable.

It really depends of your technical requirements, program architecture etc. But basically i could recommend you to use some kind of message queue service to communicate between your applications. RabbitMQ, for example.

Try ZeroMQ .

ØMQ (also known as ZeroMQ, 0MQ, or zmq) looks like an embeddable networking library but acts like a concurrency framework. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast. You can connect sockets N-to-N with patterns like fan-out, pub-sub, task distribution, and request-reply.

try use socket an pickle, pickle will transform the variable into a string, then you can recover the object on other server

just the main functions, this code doesn't work alone

socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host, port))
conn, addr = sock.accept()
conn.sendall(pickle.dumps({'somedictionary':data}))

recover data with

dict=pickle.loads(bufferreceived)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM