Created
December 14, 2013 16:24
-
-
Save cshirky/7961317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Here's FileHandler.py | |
#!/usr/bin/env python | |
import random | |
class FileHandler(object): | |
def __init__(self): | |
pass | |
def line_from_file(self, filename, query_type): | |
data = [ line.rstrip() for line in open(filename) if not line.isspace() ] | |
query_type = query_type.lower() | |
if (query_type == "random" or query_type == "rand"): | |
return random.choice(data) # Return random line | |
### And here's the test script | |
import FileHandler | |
f = FileHandler() | |
print f.line_from_file("meatball-answers.txt", "random") | |
#### But when I'm all like... | |
# cshirky$ python import_test.py | |
### ...Python's all like... | |
#Traceback (most recent call last): | |
# File "import_test.py", line 3, in <module> | |
# f = FileHandler() | |
# TypeError: 'module' object is not callable | |
### ...and same error with the 'from FileHandler import line_from_file' syntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment