#!/usr/bin/env python3
#matchPattern = re.compile(r'keywords')
import re
list = []
#matchPattern = re.compile(r'apple')
#matchPattern = re.compile(r'apple:')
#matchPattern = re.compile(r'apple=')
#matchPattern = re.compile(r'apple_name')
matchPattern = re.compile(r'apple')
file = open('/xx/xx/apple.txt','r')
while 1:
line = file.readline()
if not line:
print("Read file End or Error")
break
elif matchPattern.search(line):
pass
else:
list.append(line)
file.close()
file = open(r'/xx/xx/apple.txt', 'w')
for i in list:
file.write(i)
file.close()
macOS如何运行👆的python脚本?
macOS自带python,不用安装即可运行python脚本
首先,打开terminal,进入脚本所在的文件夹
cd 脚本所在的文件夹
然后,授权
chmod a+x 脚本文件名
执行命令,运行脚本
./脚本文件名