我有一个python脚本,经过一些计算后会生成两个格式为gnuplot输入的数据文件.
我如何从python'调用'gnuplot?
我想将以下python字符串作为输入发送到gnuplot:
"plot '%s' with lines, '%s' with points;" % (eout,nout)
Run Code Online (Sandbox Code Playgroud)
其中" EOUT "和" NOUT "是两个文件名.
PS:我宁愿不使用额外的Python模块,只有标准的API(例如gnuplot的-PY).
谢谢
我遇到的问题如下,我将用简单的例子来说明它.我编写了一个需要用户交互的python脚本,特别是它使用raw_input()函数来获取用户的输入.下面的代码只是要求用户连续输入两个数字(在每个数字之间输入),然后返回答案(惊讶,惊讶,它被称为'sum_two_numbers.py').何哼!
#! /usr/bin/python
# -------------------
# sum_two_numbers.py
# -------------------
# This script asks the user for two numbers and returns the sum!
a = float(raw_input("Enter the first number:"))
b = float(raw_input("Enter the second number:"))
print a+b
Run Code Online (Sandbox Code Playgroud)
现在,我想编写一个单独的python脚本来执行上面的脚本并将两个必要的数字"提供"给它.因此我称这个脚本为'feeder.py'.我尝试使用Python的' subprocess '模块编写这个脚本,特别是使用'Popen'类及其相关的'communic'方法.下面是试图输入数字'5'和'4'的脚本.
#! /usr/bin/python
# ----------
# feeder.py
# ----------
import subprocess
child = subprocess.Popen("./sum_two_numbers.py",stdin=subprocess.PIPE)
child.communicate("5")
child.communicate("4")
Run Code Online (Sandbox Code Playgroud)
此代码不起作用,并在执行时返回错误:
$ ./feeder.py
Enter the first number:Enter the second number:Traceback (most recent call last):
File "./sum_two_numbers.py", line 6, in <module>
b = float(raw_input("Enter the second number:")) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用“mpif90”在 Fedora 21 中编译一些代码。
首先,我使用“yum”安装 openmpi:
[root@localhost Inversion]# yum install openmpi
Loaded plugins: langpacks
Package openmpi-1.8.3-2.fc21.x86_64 already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)
但是当我使用“make”编译时,它不起作用:
[root@localhost Inversion]# make all
mpif90 -O3 -c src/dispersion.f90
make: mpif90: Command not found
Makefile:18: recipe for target 'obj' failed
make: *** [obj] Error 127
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我已经下载了 openmpi 包,但它无法编译。
python ×2
automation ×1
dnf ×1
fedora ×1
fedora-21 ×1
gnuplot ×1
openmpi ×1
popen ×1
subprocess ×1
yum ×1