我试图获得以&#34开头的行数;"在文件中
def count_the(file_url):
r = requests.get(file_url, stream=True)
pat = re.search(r'^the', file_url)
count = 0
for line in r.iter_lines():
if line.startswith('the'):`
return count += 1
答案 0 :(得分:1)
您将退货放在了错误的位置,并且您也可以避免使用re.search
。
def count_the(file_url):
r = requests.get(file_url, stream=True)
count = 0
for line in r.iter_lines():
if line.startwith('the'):
count += 1
return count
答案 1 :(得分:0)
您的代码存在一些严重缺陷:
def count_the(file_url):
r = requests.get(file_url, stream=True)
count = 0
for line in r.iter_lines():
if line.startswith('the'):`
count += 1
return count
pat
行return count
。