Skip to content

Conversation

noelevans
Copy link
Contributor

When the module is run like this:
python top_pic_comments.py
the variable sys.argv is:
['top_pic_comments.py']
So only a 0th element is available, not a 1st. Simple fix to check the length of argv

Testing below:

Before fix

With numerical arg after module name

python top_pic_comments.py 1
Title of submission:
After floods in England, swans in the street - Worcester
http://i.imgur.com/IeIaWzK.jpg

Without numerical arg - error thrown

python top_pic_comments.py
Traceback (most recent call last):
File "top_pic_comments.py", line 15, in
n_pic = int( sys.argv[1] ) if sys.argv[1] else 1
IndexError: list index out of range

Made fix

With numerical arg after module name

python top_pic_comments.py 1
Title of submission:
After floods in England, swans in the street - Worcester
http://i.imgur.com/IeIaWzK.jpg

Without numerical arg

python top_pic_comments.py
Title of submission:
After floods in England, swans in the street - Worcester
http://i.imgur.com/IeIaWzK.jpg

@CamDavidsonPilon
Copy link
Owner

Thanks, @noelevans 👍

CamDavidsonPilon added a commit that referenced this pull request Oct 12, 2015
…x-error-ch04

Fix index to list when there is no 2nd element
@CamDavidsonPilon CamDavidsonPilon merged commit 1cb1aad into CamDavidsonPilon:master Oct 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants