コード例 #1
0
raw_input("Press enter to continue."),
pprint(common_words_tuple("words.txt", 5))

raw_input("Press enter to continue.")
print "common_words_safe... ",
raw_input("Press enter to continue."),
pprint(common_words_safe("words_fail.txt", 5))
print

from question2 import (Article, Picture)
import random

print "Testing question 2"
raw_input("Press enter to continue.")
print "Creating a ugly article..."
badArticle = Article("Aliens!", "There are aliens", "Not YB")

raw_input("Press enter to continue.")
print "Showing it..."
print "\n"
badArticle.show()

raw_input("Press enter to continue.")
print "loading a better article from article.json"
betterArticle = Article.fromFile("article.json")

raw_input("Press enter to continue.")
print "Showing the better article"
print "\n"
betterArticle.show()
コード例 #2
0
from pprint import pprint # pretty print output formatting
from question1 import (common_words, common_words_min, common_words_tuple,
    common_words_safe)
# fill in the rest!
from question2 import (Article, Picture)

print "==testing question 1=="
print "common_words... ",
pprint(common_words("words.txt"))

print "common_words_min 2... ",
pprint(common_words_min("words.txt", 2))

print "common_words_min 5... ",
pprint(common_words_min("words.txt", 5))

print "common_words_min 9... ",
pprint(common_words_min("words.txt", 9))

print "common_words_tuple w/ min 5... ",
pprint(common_words_tuple("words.txt", 5))

print "common_words_safe... ",
pprint(common_words_safe("words_fail.txt", 5))

print "==testing question 2=="
article = Article("Jayant Sani joins the Crimson tech comp!", "Jayant Sani is currently working on assignment 1 of the Crimson tech comp", "Jayant Sani")
article.show()
article.save()
コード例 #3
0
pprint(common_words_min("words.txt", 5))

print "common_words_min 9... ",
pprint(common_words_min("words.txt", 9))

print "common_words_tuple w/ min 5... ",
pprint(common_words_tuple("words.txt", 5))

print "common_words_safe... ",
pprint(common_words_safe("words_fail.txt", 5))
print
"""
print "==testing question 2=="
print "making article... ",
print
a = Article()
a.author = "James"
a.headline = "Testing"
a.content = "AaBaCcDdEe FfGgHhIiJj KkLlMmNnOo..."
a.show()

print "saving to test.txt..."
a.save("test.txt")

print "trying to load from a nonexistent file..."
a.load("fake.txt")

print "trying to load from test.txt..."
a.load("test.txt")

print "trying to load from new.txt..."
コード例 #4
0
pprint(common_words("words.txt"))

print "common_words_min 2... "
pprint(common_words_min("words.txt", 2))

print "common_words_min 5... "
pprint(common_words_min("words.txt", 5))

print "common_words_min 9... "
pprint(common_words_min("words.txt", 9))

print "common_words_tuple w/ min 5... "
pprint(common_words_tuple("words.txt", 5))

print "common_words_safe... "
pprint(common_words_safe("words_fail.txt", 5))
print ""
print "Error Message above\n"

print "==testing question 2=="
print "Testing article"
art = Article("Headline here", "Article body text here", "Author")
print "Article:"
art.show()
art.save()
print ""
print "Article saved\n"
art2 = Article.load(art._uuid+".json")
print "Article loaded:"
art2.show()