Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于python的matlab findstr_Python_Matlab - Fatal编程技术网

用于python的matlab findstr

用于python的matlab findstr,python,matlab,Python,Matlab,我想将这段代码从Matlab(以下)翻译成PythonV2.7.5。你能帮我吗 fseek (fid,128,'bof'); offset = fread (fid,1,'ushort'); while (offset > 0) freeString = setstr (fread (fid,offset-2,'char'))'; if (findstr (freeString,'ACQUISITION_DATE') > 0) date_rec=(freeString (leng

我想将这段代码从Matlab(以下)翻译成PythonV2.7.5。你能帮我吗

fseek (fid,128,'bof');
offset = fread (fid,1,'ushort');
while (offset > 0)
freeString = setstr (fread (fid,offset-2,'char'))';
if (findstr (freeString,'ACQUISITION_DATE') > 0)
  date_rec=(freeString (length ('ACQUISITION_DATE '):length (freeString)));
end;
if (findstr (freeString,'ACQUISITION_TIME') > 0)
  time_rec=(freeString (length ('ACQUISITION_TIME '):length (freeString)));
end;
if (findstr (freeString,'GENERAL_CONSTANT') > 0)
  gen_const_rec=(freeString (length ('GENERAL_CONSTANT '):length (freeString)));
谢谢,,
Samuel

根据@horchler的建议,您可能只需要操作符中的

print ("hello" in "hello world")

>> True

print ("hello" in "goodbye")

>> False

print ("hello" in "world, hello")

>> True
换句话说,与Matlab的

if (findstr (freeString,'ACQUISITION_DATE') > 0)


注意-findstr(将在未来版本的Matlab中删除)将找到“长字符串中的短字符串”-而对于
运算符中的Python
,操作数的顺序很重要。

到目前为止,您自己做了什么尝试?您显示的代码中没有
end
,而
偏移量的值在
while
循环中似乎没有变化。因此,它永远不会终止(尽管它可能不会运行)。通常人们会使用
if
来实现这一点。您确定这个代码片段是正确的/完整的吗?或者基于标题,尽管有代码转储,问题仅仅在于
findstr(input_str,'test_str')>0的Python等价物是什么?
if ('ACQUISITION_DATE' in freeString):