Numpy humpy.genfromtxt从列表中输入fname参数

Numpy humpy.genfromtxt从列表中输入fname参数,numpy,genfromtxt,Numpy,Genfromtxt,我有许多文本文件作为我希望从中提取数据的计算输出: (注意:由于某些文件已被损坏,我已将副本放在我的Dropbox中。URL为) 这项工作: import numpy as np print('${d}') data = np.genfromtxt("14-7.log", usecols=(1), skip_header=27, skip_footer=1, encoding=None) print(data) np.savetxt('14-7

我有许多文本文件作为我希望从中提取数据的计算输出:

(注意:由于某些文件已被损坏,我已将副本放在我的Dropbox中。URL为)

这项工作:

 import numpy as np

    print('${d}')

    data = np.genfromtxt("14-7.log", usecols=(1), skip_header=27, 
    skip_footer=1, encoding=None)

    print(data)

    np.savetxt('14-7.dG', data, fmt='%12.9f', header='14-7')
    print(data)
产生:

runfile('/home/comp/Apps/Python/PsoVina/DeltaGTable_V_s.py', 
 wdir='/home/comp/Apps/Python/PsoVina', current_namespace=True)
 ${d}
 [-9.96090267 -8.97950478 -8.94261136 -8.91552301 -8.73650883 -8.66338714
  -8.41073971 -8.38914635 -8.29679891 -8.16845411 -8.12799082 -8.12710377
  -7.97909074 -7.94187268 -7.90076621 -7.88148523 -7.83782648 -7.8159095
  -7.72254029 -7.72034674]
 [-9.96090267 -8.97950478 -8.94261136 -8.91552301 -8.73650883 -8.66338714
  -8.41073971 -8.38914635 -8.29679891 -8.16845411 -8.12799082 -8.12710377
  -7.97909074 -7.94187268 -7.90076621 -7.88148523 -7.83782648 -7.8159095
  -7.72254029 -7.72034674]
注;打印语句用于快速检查输出,即:

# 14-7
 -9.960902669
 -8.979504781
 -8.942611364
 -8.915523010
 -8.736508831
 -8.663387139
 -8.410739711
 -8.389146347
 -8.296798909
 -8.168454106
 -8.127990818
 -8.127103774
 -7.979090739
 -7.941872682
 -7.900766215
 -7.881485228
 -7.837826485
 -7.815909505
 -7.722540286
 -7.720346742
此外,此bash脚本还可以工作:

    #!/bin/bash

    # Run.dG.list_1

    while IFS= read -r d
    do
        echo "${d}.log"

   done <ligand.list
但是,如果我运行这个bash脚本:

#!/bin/bash

 # Run.dG.list_1

 while IFS= read -r d
 do
     echo "${d}.log"
     python3 DeltaGTable_V_sl.py
 done <ligand.list
我得到:

 (base) comp@AbNormal:~/Apps/Python/PsoVina$ sh ./Run.dG.list_1.sh
     14-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     15-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     18-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     C-VX3.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
因此,日志文件标签似乎在工作区中,但是 genfromtxt未将“${d}.log”识别为fname。虽然我 谷歌搜索了我能想到的每一个术语组合,我显然 遗漏了一些东西

由于我可能有数百个文件要处理,我将不胜感激 指向问题解决方案的指针


提前感谢。

Python现在不知道shell脚本中使用的
${d}

如果要使用传递给Python脚本的命令行参数,可以使用或
sys
模块。
argparse
是一个更强大的工具,因此您可以首先尝试
sys

sys.argv[0] # name of the Python script.
sys.argv[1] # command line arguments 1
sys.argv[n] # command line arguments n

请参阅。

我可以使用以下命令创建您的错误消息:

0029:~/mypy$ python3 foobar
python3: can't open file 'foobar': [Errno 2] No such file or directory
foobar
是一个随机名称,显然不存在于Python路径中


因此,您甚至还没有开始使用
DeltaGTable\u V_sl.py
,更不用说遇到
genfromtxt
的问题了。因此,您的大多数问题都不相关。

无法打开错误意味着python脚本不在python的路径上。它甚至还没有开始运行脚本。是的,${d}不是向脚本中添加变量的方式,但这不是直接的ereor。
 (base) comp@AbNormal:~/Apps/Python/PsoVina$ sh ./Run.dG.list_1.sh
     14-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     15-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     18-7.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
     C-VX3.log
     python3: can't open file 'DeltaGTable_V_sl.py': [Errno 2] No such file 
     or directory
sys.argv[0] # name of the Python script.
sys.argv[1] # command line arguments 1
sys.argv[n] # command line arguments n
0029:~/mypy$ python3 foobar
python3: can't open file 'foobar': [Errno 2] No such file or directory