首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >很难通过python用qhull管道

很难通过python用qhull管道
EN

Stack Overflow用户
提问于 2013-09-02 03:38:49
回答 1查看 302关注 0票数 0

我在python中通过QHull命令时遇到了问题。我现在正试图这样做:

代码语言:javascript
复制
input_command = "rbox c " + str(qpoints) + " | qconvex FQ FV n"
command = subprocess.Popen(input_command.split(" "), stdout=subprocess.PIPE)
print command.communicate()[0]

在这里,qpoint是格式化的,这样input_command就会以如下方式结束:

代码语言:javascript
复制
rbox c P0,0,0 P0,0,2 P0,2,0 P0,2,2 P2,0,0 P2,0,2 P2,2,0 P2,2,2 | qconvex FQ FV n

但不幸的是,这只会打印出q凸的用法:

代码语言:javascript
复制
qconvex- compute the convex hull.  Qhull 2012.1 2012/02/18
    input (stdin): dimension, number of points, point coordinates
    comments start with a non-numeric character

options (qconvex.htm):
    Qt   - triangulated output
    QJ   - joggled input instead of merged facets
    Tv   - verify result: structure, convexity, and point inclusion
    .    - concise list of all options
    -    - one-line description of all options

output options (subset):
    s    - summary of results (default)
    i    - vertices incident to each facet
    n    - normals with offsets
    p    - vertex coordinates (includes coplanar points if 'Qc')
    Fx   - extreme points (convex hull vertices)
    FA   - report total area and volume
    FS   - compute total area and volume
    o    - OFF format (dim, n, points, facets)
    G    - Geomview output (2-d, 3-d, and 4-d)
    m    - Mathematica output (2-d and 3-d)
    QVn  - print facets that include point n, -n if not
    TO file- output results to file, may be enclosed in single quotes

examples:
    rbox c D2 | qconvex s n                    rbox c D2 | qconvex i
    rbox c D2 | qconvex o                      rbox 1000 s | qconvex s Tv FA
    rbox c d D2 | qconvex s Qc Fx              rbox y 1000 W0 | qconvex s n
    rbox y 1000 W0 | qconvex s QJ              rbox d G1 D12 | qconvex QR0 FA Pp
    rbox c D7 | qconvex FA TF1000

我在网上读到了一些在python调用中包含管道时必须采取的额外步骤的例子。但我无法让他们的任何例子发挥作用,而且对于发生了什么几乎没有任何解释。有人能向我解释一下这里的代码片段吗?它能工作吗?

我还试着从文件中读取一个函数的结果。例如,我尝试从文件中读取rbox的结果:

python代码:

代码语言:javascript
复制
input_command =  "qconvex FQ FV n < rbox.txt"
    command = subprocess.Popen(input_command.split(" "), shell=True)
    result = command.communicate()
    return result

数据:

代码语言:javascript
复制
3 rbox c P1,1,1 P1,1,3 P1,3,1 P1,3,3 P3,1,1 P3,1,3 P3,3,1 P3,3,3
16
     1      1      1 
     1      1      3 
     1      3      1 
     1      3      3 
     3      1      1 
     3      1      3 
     3      3      1 
     3      3      3 
  -0.5   -0.5   -0.5 
  -0.5   -0.5    0.5 
  -0.5    0.5   -0.5 
  -0.5    0.5    0.5 
   0.5   -0.5   -0.5 
   0.5   -0.5    0.5 
   0.5    0.5   -0.5 
   0.5    0.5    0.5 

不过,这仍然只是打印出QConvex的描述。奇怪的是,它在命令行中运行得非常好,只是不是通过python。即使我不能让管道工作,我绝对需要从文件到工作的读取。有人知道做这个函数调用的诀窍吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-02 05:06:01

  • 如果使用shell特性(如shell=True )或使用纯Python重写命令,请参见换壳管线
  • 如果使用shell=True,则将命令作为医生们中指定的字符串传递
代码语言:javascript
复制
from subprocess import check_output as qx

output = qx("rbox c {qpoints} | qconvex FQ FV n".format(qpoints=qpoints),
            shell=True)
print output
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18565369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档