June 2017
Beginner
352 pages
8h 39m
English
That last change actually breaks our main() since it's not passing the new url argument. When running our module as a standalone program, we'll need to accept the URL as a command line argument. Access to command line arguments in Python is through an attribute of the sys module called argv which is a list of strings. To use it we must first import the sys module at the top of our program:
import sys
We then get the second argument (with an index of one) from the list:
def main(): url = sys.argv[1] words = fetch_words(url) print_items(words)
And of course this works as expected:
$ python3 words.py http://sixty-north.com/c/t.txtItwasthebestoftimes
This looks fine until we realize that we can't usefully test ...
Read now
Unlock full access