我在尝试加入Matlab中不同来源的代码时遇到了问题,我真的不知道如何处理它。基本上,我有一些Python代码用于从命令行调用的压缩算法,该算法本身使用子进程来运行并与编译为二进制文件的C ++代码进行通信。
Python中的函数(它是更大对象的一部分)如下所示:
system('./temp_script')
为了最大限度地减少移植问题,我决定通过系统命令完全间接地与Matlab集成,将脚本与所有组件放在一起并通过
运行它cd /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis
python Lexis.py -f i /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis/aabb.txt >> /home/ben/Documents/MATLAB/StructureDiscovery/+sd/Lexis/lexis_results.txt
其中temp_script是可执行的,如下所示:
Traceback (most recent call last):
File "Lexis.py", line 762, in <module>
g.GLexis(quietLog, rFlag, functionFlag, costWeight)
File "Lexis.py", line 191, in GLexis
(maximumRepeatGainValue, selectedRepeatOccs) = self.__retreiveMaximumGainRepeat(normalRepeatType, CostFunction.EdgeCost)
File "Lexis.py", line 242, in __retreiveMaximumGainRepeat
repeats = self.__extractRepeats(repeatClass)
File "Lexis.py", line 302, in __extractRepeats
process.stdin.write(' '.join(map(str,self.__concatenatedDAG)))
IOError: [Errno 32] Broken pipe
现在我在Ubuntu 16.04中运行它,从终端运行脚本。但是,从Matlab运行相同的脚本会给我带来错误
File "Lexis.py", line 251, in __retreiveMaximumGainRepeat
idx = map(int,repeatStats[2][1:-1].split(','))[0]
ValueError: invalid literal for int() with base 10: 'ersio'
或错误
repeats = self.__extractRepeats(repeatClass)
for r in repeats: #Extracting maximum repeat
repeatStats = r.split()
idx = map(int,repeatStats[2][1:-1].split(','))[0]
我无法弄清楚什么时候能得到哪一个。
repeatStats的相关片段是
import requests
from bs4 import BeautifulSoup
url = 'http://projects.chicagoreporter.com/settlements/search/cases'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text,"html.parser")
for link in soup.findAll('div',{'class':'case-payment'}):
href = "http://projects.chicagoreporter.com/settlements/search/cases"
title = link.string
print(title)
我真的不知道Matlab通过系统调用某些内容并直接从终端调用它之间有什么不同,所以我不知道出了什么问题。在OSX 10.11上,完全相同的代码可以工作。
有没有人知道Matlab的系统命令的内部工作原理以及为什么它可能无法允许Python调用子进程?
任何帮助将不胜感激!
答案 0 :(得分:0)
repeats = self.__extractRepeats(repeatClass)
for r in repeats: #Extracting maximum repeat
repeatStats = r.split()
idx = map(int,repeatStats[2][1:-1].split(','))[0]
假设你的repeatStats [2]是xersiox,10
然后,repeatStats [2] [1:-1]变为ersiox,1
然后,repeatStats [2] [1:-1] .split(&#39;,&#39;)会产生一个列表[&#39; ersio&#39;,&#39; 1&#39;]
您已将整个列表传递给整个语句
idx = map(int,repeatStats[2][1:-1].split(','))[0]
# it looks like this idx = map(int, ['ersio', '1'])[0]
# it picks the first item from the list, which is 'ersio', which does not have any numerical in that.
请尝试以下方法:
idx = map(int,repeatStats[2][1:-1].split(',')[1])[0]
# or provide an index of the item in the list, which has a number in it.