-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwords.py
More file actions
executable file
·52 lines (37 loc) · 1 KB
/
Copy pathwords.py
File metadata and controls
executable file
·52 lines (37 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
""" Retrieve and print words from a URL.
Usage:
python3 words.py<URL>
"""
import sys
from urllib import request
def fetch_words(url):
"""Fetch a list of words from a URL.
Args:
url: The URL of a UTF-8 text document.
Returns:
A list of string containing the words from the document.
"""
story = request.urlopen(url)
story_words = []
for line in story:
line_words = line.decode('utf-8').split()
for word in line_words:
story_words.append(word)
return story_words
def print_items(items):
""" Print items one per line.
Args:
An iterable series of printable items.
"""
for item in items:
print(item)
def main(url):
""" Print each word from a text document from a URL.
Args:
url: The URL of a UTF-8 text document.
"""
words = fetch_words(url)
print_items(words)
if __name__ == '__main__':
main(sys.argv[1]) # The 0th argument is the module filename