0

我想为 Python v2.7.5 从 Matlab(下)翻译这段代码。你能帮助我吗?

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)));

谢谢你,塞缪尔

4

1 回答 1

0

根据@horchler 的建议,您可能只需要in运算符:

print ("hello" in "hello world")

>> True

print ("hello" in "goodbye")

>> False

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

>> True

换句话说,相当于 Matlab 的

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

if ('ACQUISITION_DATE' in freeString):

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

于 2013-08-05T20:18:35.803 回答