Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.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 从文本文件中提取公式中编码的值_Python - Fatal编程技术网

Python 从文本文件中提取公式中编码的值

Python 从文本文件中提取公式中编码的值,python,Python,在文本文件中,我有一个特定的行,如: ZONE, T="test", I =100, J= 175, F = POINT 我想用python提取“I”和“J”的值 你有什么建议吗?谢谢。例如,我被写在一个文本文件名filename.txt中,在这个文件上它被写为I=100,我将使用re.search查找值 import re f = open('filename.txt', 'a').readlines() for i in f: value = i.rstrip() n =

在文本文件中,我有一个特定的行,如:

ZONE, T="test", I =100, J=  175, F = POINT
我想用python提取“I”和“J”的值


你有什么建议吗?谢谢。

例如,我被写在一个文本文件名filename.txt中,在这个文件上它被写为I=100,我将使用re.search查找值

import re

f = open('filename.txt', 'a').readlines()
for i in f:
   value = i.rstrip()
   n = re.search(r'I = (.*)', value)
   i = n.group(1)
   print("I = " + i)

清除空白,用逗号分隔,查找“I=”和“J=”,取后面的内容
import re

f = open('filename.txt', 'a').readlines()
for i in f:
   value = i.rstrip()
   n = re.search(r'I = (.*)', value)
   i = n.group(1)
   print("I = " + i)