当前位置: 首页>>代码示例>>Python>>正文


Python question.Question类代码示例

本文整理汇总了Python中question.Question的典型用法代码示例。如果您正苦于以下问题:Python Question类的具体用法?Python Question怎么用?Python Question使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Question类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

    def parse(self, string):
        re_index  = r'\**\s*(?:[A-Ea-e]\.|\(?[A-Ea-e]\))'
        re_body   = r'.+'
        re_option = r'({index}\s+{body})'.format(index=re_index, body=re_body)
        self._tokenize(string)

        # spin thru the input chunks two at a time, the first being the
        # stem, presumably, and the second being the option group
        for st_index in range(0, len(self._tokens), 2):
            op_index = st_index +1
            if op_index < len(self._tokens):
                question = Question()

                stem = re.search(r'[0-9]+(?:\.|\s).+$', self._tokens[st_index], re.DOTALL)
                #~ stem = re.search(r"\n*((?:[0-9]*\.*\s*).+)$", self._tokens[st_index], re.DOTALL)
                #~ stem = re.search(r"(?:[0-9]+\s+(?:.|\n)+$)+?|(?:\n*.+$)", self._tokens[st_index])
                question.stem = stem.group().strip() if stem else self._tokens[st_index] 

                options = [o.strip() for o in re.split(re_option, self._tokens[op_index]) if o.strip()]
                for option in options:
                    question.options.append(option)

                self._questions.append(question)

        return self
开发者ID:manisoftwartist,项目名称:choice-parser,代码行数:25,代码来源:parser.py

示例2: loadSurvey

def loadSurvey(filename):
    from question import Question
    from answer import Answer
    survey = None
    f = open(filename, "r")
    if f is not None:
        s = ""
        b = f.read(512)
        while len(b):
            s += b
            b = f.read(512)
        f.close()
        sd = jsonpickle.decode(s)
        survey = Survey()
        survey.name = sd['name']
        survey.questions = {}
        for qd in sd['questions'].values():
            question = Question()
            question.id = qd['id']
            question.name = qd['name']
            question.answers = {}
            for ad in qd['answers'].values():
                answer = Answer()
                answer.id = ad['id']
                answer.value = ad['value']
                answer.selected = ad['selected']
                answer.editable = ad['editable']
                question.answers[answer.id] = answer
            survey.questions[question.id] = question
    return survey
开发者ID:rbianchi66,项目名称:survey,代码行数:30,代码来源:survey.py

示例3: test_creation

 def test_creation(self):
     q = {'name': 'q1', 'text': 'Random question one, choose a.', 'answers': 
             [{'value': 'a', 'text': 'a'}, {'value': 'b', 'text': 'b'}, 
              {'value': 'c', 'text': 'c'},{'value': 'd', 'text': 'd'}]
         }
     question = Question(q)
     assert question.name == q['name'] and question.text == q['text'] and question.answers == q['answers']
     question.save()
开发者ID:TxSSC,项目名称:the-questionator,代码行数:8,代码来源:questions.py

示例4: test_blank_name

 def test_blank_name(self):
     question = Question()
     question.text = 'Blank test question'
     question.answers = []
     try:
         question.save()
     except KeyError, e:
         print 'Adding blank question failed: %s' % e
开发者ID:TxSSC,项目名称:the-questionator,代码行数:8,代码来源:questions.py

示例5: get_question

def get_question(question_id):
    if Question.is_null() == False: 
    	rows = Question.query(Question.serial_no==question_id).fetch()
        if len(rows) == 1:
            return dict(total= Question.count(), detail = rows[0])
        else:
            return empty_question()
    else:
        return empty_question()
开发者ID:lanesky,项目名称:boki2exam,代码行数:9,代码来源:main.py

示例6: test_duplicate

 def test_duplicate(self):
     q = {'name': 'q2', 'text': 'Random question one, choose a.', 'answers': 
             [{'value': 'a', 'text': 'a'}, {'value': 'b', 'text': 'b'}, 
              {'value': 'c', 'text': 'c'},{'value': 'd', 'text': 'd'}]
         }
     question = Question(q)
     assert question.name == q['name'] and question.text == q['text'] and question.answers == q['answers']
     question.save()
     try:
         question.save()
     except KeyError, e:
         print 'Trying to save duplicate: %s' % e
开发者ID:TxSSC,项目名称:the-questionator,代码行数:12,代码来源:questions.py

示例7: test_illegal_keys

	def test_illegal_keys(self):
		self.assertFalse(Question.iskey("")[0], "Empty string")
		self.assertFalse(Question.iskey("   ")[0], "Whitespace only")
		self.assertFalse(Question.iskey("  key")[0], "Leading whitespace")
		self.assertFalse(Question.iskey("end\t")[0], "Traling tabulation")
		self.assertFalse(Question.iskey("*$/\\")[0], "Non-alphanumeric characters")
		self.assertFalse(Question.iskey("end")[0], "Reserved keyword")
		self.assertFalse(Question.iskey("photoVisible")[0], "Reserved keyword")
		self.assertFalse(Question.iskey(32768)[0], "Not a string")
		self.assertFalse(Question.iskey("\n")[0], "Illegal escape character")
开发者ID:cobismith,项目名称:geotagx-project-template,代码行数:10,代码来源:test_question.py

示例8: questions

def questions():
    form = NewQuestionForm(request.form)
    if request.method == 'POST' and form.validate():
        question = Question(form.category.data, form.question.data,
                            form.option_a.data, form.option_b.data,
                            form.option_c.data, form.option_d.data,
                            form.answer.data)
        question.save()
        flash('Question successfully created!', 'positive')
        return render_template('question_created.html', question=question, amount=Question.size())
    elif request.method == 'POST' and not form.validate():
        flash('Oops, your submitted question appears to be invalid.', 'negative')
        return render_template('question_new.html', form=form, amount=Question.size())
    else:
        return render_template('invalid_request.html')
开发者ID:sasalatart,项目名称:triviapp,代码行数:15,代码来源:routes.py

示例9: accept_input

def accept_input():
  content = request.args.get('content', '')
  number = request.args.get('from', '')
  # check for malicious URLs
  if url_check(content):
    print "This number is a spammer: %(number)s" % {"number": number}
    return
  if number == '447860033028':
    #no infinite loop 4 u
    return
  question = Question(content,number)
  question.ask()

  # debug statements below
  print("%(content)s from %(number)s." % {"content": question.message, "number": question.number})
  return "%(content)s from %(number)s." % {"content": question.message, "number": question.number} 
开发者ID:jonnydark,项目名称:ask-yoda,代码行数:16,代码来源:ask_yoda.py

示例10: ask

    def ask(self, question, answer_type = str, **configs):
        self.question = Question(question, answer_type)
        self.answer = ""
        for key, value in configs.iteritems():
            self.question.__dict__[key] = value

        if self.question.gather:
            return self.gather()

        self.say(self.question.question)
        # retry until the correct answer
        while True:
            try:
                self.answer = self.question.answer_or_default(self.get_response())
                self.answer = self.question.change_case(self.answer)
                self.__class__(self.input, self.output)
                self.question.update()
                if not self.question.valid_answer(self.answer):
                    self.explain_error("not_valid")
                    raise QuestionError()
                self.answer = self.question.convert(self.answer)
            except QuestionError:
                pass
            else:
                self.question = None
                break
        return self.answer
开发者ID:Krazylee,项目名称:askme,代码行数:27,代码来源:__init__.py

示例11: test_valid_keys

	def test_valid_keys(self):
		self.assertTrue(Question.iskey("A")[0], "Single-character")
		self.assertTrue(Question.iskey("thisIsALongKey")[0], "Multi-character")
		self.assertTrue(Question.iskey("--")[0], "Hyphens")
		self.assertTrue(Question.iskey("--key")[0], "Leading hyphens")
		self.assertTrue(Question.iskey("_")[0], "Underscores")
		self.assertTrue(Question.iskey("__key")[0], "Leading underscores")
		self.assertTrue(Question.iskey("_now-y0u_4re-pushing-1t")[0], "Mixed characters")
		self.assertTrue(Question.iskey("_end")[0], "Not a reserved keyword")
开发者ID:cobismith,项目名称:geotagx-project-template,代码行数:9,代码来源:test_question.py

示例12: test_should_return_html_for_single_line_answer_question

 def test_should_return_html_for_single_line_answer_question(self):
     actual = Question.single_line_answer("question")
     expected = '''\
         <div id="1">
             question <input type="text" id=1></input>
         </div>
     '''
     self.assertEquals(HTMLReader(expected).to_s(), HTMLReader(actual).to_s())
开发者ID:rgan,项目名称:quizgen,代码行数:8,代码来源:question_test.py

示例13: test_should_return_html_for_multi_line_answer_question

 def test_should_return_html_for_multi_line_answer_question(self):
     actual = Question.multi_line_answer("question")
     expected = '''\
         <div id="1">
             question <textarea rows=10 cols=30 id=1></textarea>
         </div>
     '''
     self.assertEquals(HTMLReader(expected).to_s(), HTMLReader(actual).to_s())
开发者ID:rgan,项目名称:quizgen,代码行数:8,代码来源:question_test.py

示例14: test_should_return_html_for_multi_choice_answer_question

 def test_should_return_html_for_multi_choice_answer_question(self):
     actual = Question.multi_choice("question", "a1", "a2")
     expected = '''\
         <div id="1">
             question <input type=checkbox id="1_1">a1</input><input type=checkbox name="1_2">a2</input>
         </div>
     '''
     self.assertEquals(HTMLReader(expected).to_s(), HTMLReader(actual).to_s())
开发者ID:rgan,项目名称:quizgen,代码行数:8,代码来源:question_test.py

示例15: test_should_return_html_for_single_choice_question

 def test_should_return_html_for_single_choice_question(self):
     actual = Question.single_choice("question", "a1", "a2")
     expected = '''\
         <div id="1">
             question <input type=radio name="1">a1</input><input type=radio name="1">a2</input>
         </div>
     '''
     self.assertEquals(HTMLReader(expected).to_s(), HTMLReader(actual).to_s())
开发者ID:rgan,项目名称:quizgen,代码行数:8,代码来源:question_test.py


注:本文中的question.Question类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。