I have a document that defines several functions (assignment_2a.py). I'm trying to achieve the following:
Modify the [assignment_2a.py](../code/assignment_2a.py) to be able to run
the program `make_random_story` from the command line:
```
$ python assignment_2a.py '../data/alice.txt' 2 200
```
I know how to run this specified function by going into ipython, and it works fine. But how do I alter the document so I can run it from the command line using the above command, i.e., specifying the input variables in that format?
UPDATE: I updated the function as suggested in the comments and am getting the following error message:
COMMAND LINE INPUT:
python assignment_2a.py '../data/alice.txt' 2 200
COMMAND LINE OUTPUT:
Traceback (most recent call last):
File "assignment_2a.py", line 202, in <module>
make_random_story(*sys.argv[1:])
File "assignment_2a.py", line 189, in make_random_story
for i in xrange(0,num_words):
TypeError: an integer is required
And here's the relevant updated function text:
def make_random_story(f, n_gram=2, num_words=200):
f = open(f)
random.seed('Is the looking-glass is half full or half-empty?')
story = ''
if n_gram==1:
d = associated_unigrams(f)
elif n_gram==2:
d = associated_bigrams(f)
elif n_gram==3:
d = associated_trigrams(f)
for i in xrange(0,num_words):
chosenkey = random.choice(d.keys())
story += random.choice(d[chosenkey]) + " "
print story
f.close()
if __name__ == '__main__':
make_random_story(*sys.argv[1:])