別のファイルが取得して使用する HTML コードを返す関数があります。ただし、コードは 1 つの大きな段落で返されるため、適切な行に分割する必要があります。これは print で十分に簡単ですが、次のファイルが取得できるようにするには、そのように戻す必要があります。
今すぐ出力:
'<abbr title = 6 style="font-size: 800%">spam</abbr> <abbr title = 5 style="font-size: 800%">page</abbr> <abbr title = 4 style="font-size: 800%">penguin</abbr> <abbr title = 2 style="font-size: 800%">stem</abbr> <abbr title = 1 style="font-size: 800%">has</abbr> <abbr title = 1 style="font-size: 800%">love</abbr> <abbr title = 1 style="font-size: 800%">these</abbr> <abbr title = 1 style="font-size: 800%">spamming</abbr> <abbr title = 1 style="font-size: 800%">spammer</abbr> <abbr title = 1 style="font-size: 800%">your</abbr> <abbr title = 1 style="font-size: 800%">webpage</abbr> <abbr title = 1 style="font-size: 800%">program</abbr> <abbr title = 1 style="font-size: 800%">stemming</abbr> <abbr title = 1 style="font-size: 800%">stemmer</abbr> <abbr title = 1 style="font-size: 800%">were</abbr> <abbr title = 1 style="font-size: 800%">word</abbr> <abbr title = 1 style="font-size: 1600.0%">by</abbr> '
望ましい出力:
<abbr title = 6 style="font-size: 800%">spam</abbr>
<abbr title = 5 style="font-size: 800%">page</abbr>
<abbr title = 4 style="font-size: 800%">penguin</abbr>
等.....
これが私が使用している機能です:
def mtcURL(URL):
a = getURL(URL)
COUNT = a[0]
WORD = a[1]
NUMBER = 800
i = 0
all_lines = ""
while i < len(a[1]):
if i == len(COUNT)-1:
ratio = COUNT[i] / 2
NUMBER = NUMBER / (ratio)
else:
try:
ratio = COUNT[i]/COUNT[i+1]
except IndexError:
pass
first = '<abbr title = '
second = 'style="font-size: '
third = '%">'
fourth = '</abbr> '
htmlLine = first + str(COUNT[i])+ ' ' + second + str(NUMBER)+ third + WORD[i] + fourth
all_lines += htmlLine
i += 1
return all_lines