Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 60 lines (49 sloc) 1.394 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
import os
import re
import sys

def show(question, py_file, guesses=None, is_code=False):
    PY_VERSION = sys.version
    PY_VERSION = PY_VERSION.replace("\n","")
    PY_FILE_BASE = py_file.replace(".py", "")
    SEP = "=" * 80
    question = question.strip()

    # Get the answer
    answer = ''
    ans_file = "answer."
    ans_file += py_file.replace("py","txt")
    if os.path.exists(ans_file):
        answer = open(ans_file).read()

    if is_code:
        # Grab the code below the hash marks
        whole_file = open(py_file).read()
        code = re.search(string=whole_file,
                         pattern="(?s)(#{10,}.*)").group(1)

    # Get the guesses
    if guesses:
        # Use the value of guesses passed-in
        pass
    else:
        guessesFilename = "guesses.%s.txt" % PY_FILE_BASE

        if os.path.exists(guessesFilename):
            guesses = open(guessesFilename).read()
        else:
            guesses = ''

    print(SEP)
    print("QUESTION [%s]:" % PY_FILE_BASE)
    print(SEP)
    print(question)

    if is_code:
        print(code)

    print(SEP)
    print("GUESSES:")
    print(SEP)
    print(guesses)


    if py_file and not is_code:
        print(SEP)
        print("ANSWER:")
        print(SEP)
        print(answer)

    if is_code:
        print(SEP)
        print("ANSWER / OUTPUT: [Python version: %s]" % PY_VERSION)
        print(SEP)
Something went wrong with that request. Please try again.