2

statement.text in chatterbot and Django integration returns

{'text': u'How are you doing?', 'created_at': datetime.datetime(2017, 2, 20, 7, 37, 30, 746345, tzinfo=<UTC>), 'extra_data': {}, 'in_response_to': [{'text': u'Hi', 'occurrence': 3}]}

I want a value of text attribute so that it prints How are you doing?

Raja Simon
  • 10,126
  • 5
  • 43
  • 74
Fahad Shahid
  • 136
  • 1
  • 6

2 Answers2

1

What you got is dictionary. Value of dictionary can be obtained by get() function. You can also use dict['text'], but it does not perform error checking. get function returns None if key is not present.

Ojas Kale
  • 2,067
  • 2
  • 24
  • 39
1

The chatterbot return the json object(dict) so you can use the dictionary operations like following

[1]: data = {'text': u'How are you doing?', 'created_at': datetime.datetime(2017, 2, 20, 7, 37, 30, 746345, tzinfo=<UTC>), 'extra_data': {}, 'in_response_to': [{'text': u'Hi', 'occurrence': 3}]}

[2]: data['text'] or data.get('text')[this approch is good].
Cadmus
  • 665
  • 7
  • 13