如何获取括号内的元素并将它们放入文件中?
我(我) 你(你) 他(他) 她(她)
提前致谢, 阿迪亚
最佳答案
import re
txt = 'me (I) you (You) him (He) her (She)'
words = re.findall('\((.+?)\)', txt)
# words returns: ['I', 'You', 'He', 'She']
with open('filename.txt', 'w') as out:
out.write('\n'.join(words))
# file 'filename.txt' contains now:
I
You
He
She
关于python - 抓取括号内的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3882407/