如何在Python和Go语言之间共享变量?

huangapple go评论95阅读模式
英文:

how to share variable between python and go language?

问题

我需要知道如何在两个程序之间共享变量,
基本上,Go程序需要写入一个变量,比如一个字符串,而Python程序需要读取这个变量。
请帮助我,提前感谢你。

英文:

i need to know how share variable between two program,
basically the go program have to write a variable ,like a string, and the python program have to read this variable.
Please help me, thank you in advance.

答案1

得分: 1

使用标准流。使用简单的printf类型命令将字符串打印到标准输出。然后在Python中使用raw_input()读取它。

像这样运行这两个程序:

./output | ./read.py

英文:

use standard streams. use a simple printf type command to print the string to stdout. then read it with a raw_input() in python.

run the two programs like so:

./output | ./read.py

答案2

得分: 1

在Windows中,两个进程之间进行通信的最常见方式是“命名管道”(也可以是tcp/ip、web服务等)。

一种丑陋但更轻量的方式是将值写入文件,然后从Python中读取。

英文:

In Windows, most common way to do communication between two processes is "Named Pipe" (could also be tcp/ip, web service, etc...).

A ugly but lighter way is to write the value to a file, and read it from python.

huangapple
  • 本文由 发表于 2012年1月4日 00:37:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/8715435.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定