在python 2.x中,我可以这样做:
import sys, array
a = array.array('B', range(100))
a.tofile(sys.stdout)Run Code Online (Sandbox Code Playgroud)
然而,现在,我得到了一个TypeError: can't write bytes to text stream.我应该使用一些秘密编码吗?
我在使用子进程模块重定向另一个程序的stdio时遇到问题.只是从stdout读取导致挂起,并且Popen.communicate()可以工作,但它在读/写后关闭管道.实现这个最简单的方法是什么?
我在Windows上玩这个:
import subprocess
proc = subprocess.Popen('python -c "while True: print \'Hi %s!\' % raw_input()"',
shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
while True:
proc.stdin.write('world\n')
proc_read = proc.stdout.readline()
if proc_read:
print proc_readRun Code Online (Sandbox Code Playgroud) 我在C++中为node.js编写了一个插件,遇到了一个小问题.我想在我的模块目录中读取配置文件,但无法以通常的方式找到它(__dirname),因为在C++中,全局对象似乎是空的.
有没有正确的方法来做到这一点,还是我需要诉诸黑客?