2011-03-26 26 views
3

如何在使用构建脚本构建脚本时为Python指定参数?在脚本的shebang行中添加Python参数(脚本使用buildout和zc.recipe.egg:脚本)

这里是我的buildout.cfg:

[buildout] 
parts = python 
develop = . 

[python] 
recipe = zc.recipe.egg:scripts 
eggs = myproject 

而且setup.py:

from setuptools import setup, find_packages 

setup(
    name = 'myproject', 
    packages = find_packages(), 
    entry_points = """ 
    [console_scripts] 
    myscript = myproject:main 
    """, 
) 

我得到这个配置以下家当:

$ pip install . 
$ head -n1 /usr/local/bin/myscript 
#!/usr/bin/python 

而且我想这样的:

#!/usr/bin/python -u 

如何操作?我尝试将arguments = -uinterpreter = python -u添加到buildout.cfg。它没有工作。

回答

3

可以使用os.fdopen在filenumber通过重新开放标准输入和标准输出迫使无缓冲I/O从你的Python脚本中:

import sys, os 
unbuffered = os.fdopen(sys.stdout.fileno(), 'w', 0) 

然后,您可以重新分配sys.stdout的,如果你想使用使用标准输出或标准输入其它模块或建造程序:

sys.stdout = unbuffered 

另见unbuffered stdout in python (as in python -u) from within the program

相关问题