我有一个类似的文本文件-
$ abc
defghjik
am here
not now
$ you
are not
here but go there
$ ....
我想提取两个$符号之间的文本,然后将该文本放入列表或字典中。如何通过读取文件在python中执行此操作?
我尝试了正则表达式,但它为我提供了文本文件的备用值:
f1 = open('some.txt','r')
lines = f1.read()
x = re.findall(r'$(.*?)$', lines, re.DOTALL)
我希望输出如下所示-['abc','defghjik','am here','not now'] ['you','are','here but go there']
对不起,但是对于python还是一个新手,我想学习一下,感谢您的帮助!谢谢!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句