Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Selecting a random choice more elegantly without the need to call see…

…d(), len(), etc.
  • Loading branch information...
commit 8159c43990529ee7913612719894ede8ba205bef 1 parent 05a3d05
@NickPresta NickPresta authored
Showing with 4 additions and 6 deletions.
  1. +4 −6 quotation_selector.py
View
10 quotation_selector.py
@@ -1,13 +1,11 @@
-import random
+from random import choice
class QuotationSelector(object):
def __init__(self, quotes_filename):
- random.seed()
- quotes_file = open(quotes_filename)
- self.quotes = quotes_file.readlines()
+ with open(quotes_filename) as quotes_file:
+ self.quotes = quotes_file.readlines()
def select(self):
- index = random.randint(0, len(self.quotes) - 1)
- return self.quotes[index].strip()
+ return choice(self.quotes).strip()
Please sign in to comment.
Something went wrong with that request. Please try again.