Nonetype Error

36 views
Skip to first unread message

Maurice Waka

unread,
Jun 28, 2018, 1:30:12 PM6/28/18
to web2py-users
Am calling functions from a list as follows:

''.join([x() for x in corpus])

A function could be like this:
def findWholeWord(w):
   
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search

item = ['ii']
fnval
= ['i', 'we', 'cake', 'love', 'time', ]

fadmin
= ['admin','give',]
G3
= [one(), two(), three()]
G4
= [four(), five()]
l
= []
def testing():    
   
while True:
       
for c in fnval:            
           
if findWholeWord(c)(item[0]):            
               
print 'yes'
       
for c in fadmin:
           
if findWholeWord(c)(item[0]):
               
print 'yes admin'
       
break


Sometimes the functions return a None value.AM also concerned about the function not slowing down the app.
Regards

To avoid this  

<type 'exceptions.TypeError'> 'NoneType' object is not callable

 I want to reply to the user with a statement like  "I can't find an answer. Please refresh your question"

How can I do this

Leonel Câmara

unread,
Jun 28, 2018, 1:55:52 PM6/28/18
to web...@googlegroups.com
Where and how is the list of functions to be called (corpus) defined? The mistake is obviously there as one of the values in corpus is not a function it's a None. 
 
Also if the functions sometimes return a None value (the error would be different but) you cannot join them like that since None is not a string so you need to filter out the Nones with something like
''.join(y for y in [x() for x in corpus] if y is not None)

Maurice Waka

unread,
Jun 28, 2018, 2:05:41 PM6/28/18
to web...@googlegroups.com
Corpus is defined in the controller. 

On Thu, 28 Jun 2018, 20:55 Leonel Câmara <leonel...@gmail.com> wrote:
Where and how is the list of functions to be called (corpus) defined? The mistake is obviously there as one of the values in corpus is not a function it's a None. 
 
Also if the functions sometimes return a None value (the error would be different but) you cannot join them like that since None is not a string so you need to do filter out the Nones with something like
''.join(y for y in [x() for x in corpus] if y is not None)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/KRSp3bD-LDU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Jun 28, 2018, 2:29:25 PM6/28/18
to web2py-users
Maurice telling me corpus is defined in the controller doesn't help me at all, I need to see how you are picking the functions you put there to see why one could be None. A possible reason is that you have a dictionary of keys with a function as the value of each key, you then do a get from that dictionary which will return a None if the function isn't there.

Maurice Waka

unread,
Jun 29, 2018, 2:21:11 AM6/29/18
to web...@googlegroups.com
My apologies.I got carried away by an issue.
Cotroller code:
from applications.....service.main import get_word, get_name, get_index, testing
def views:
    corpus = [get_name, get_words, get_index, testing]##imported functions
    result = ''.join(y for y in [x() for x in corpus] if y is not None)
  return dict(form=form, result=result)

On Thu, Jun 28, 2018 at 9:29 PM Leonel Câmara <leonel...@gmail.com> wrote:
Maurice telling me corpus is defined in the controller doesn't help me at all, I need to see how you are picking the functions you put there to see why one could be None. A possible reason is that you have a dictionary of keys with a function as the value of each key, you then do a get from that dictionary which will return a None if the function isn't there.

--

Leonel Câmara

unread,
Jun 29, 2018, 6:58:06 AM6/29/18
to web2py-users
Ok, the error is not there, the error is inside one of the corpus functions.

Maurice Waka

unread,
Jun 29, 2018, 7:39:35 AM6/29/18
to web...@googlegroups.com
Thanks.
What I want is how to reply with a string like:, 'I can not find a reply, please try again'. Am expecting errors when for example some one types random figures or letters that the function cannot process. A function can processe a request such as 'what's your name', but not 'ejududuurjrrh bjuejhr 1234'
Regards 

On Fri, 29 Jun 2018, 13:58 Leonel Câmara <leonel...@gmail.com> wrote:
Ok, the error is not there, the error is inside one of the corpus functions.

--

Leonel Câmara

unread,
Jun 29, 2018, 8:41:18 AM6/29/18
to web2py-users
If you want to do that right you need to do natural language processing e.g. using python nltk.

Maurice Waka

unread,
Jun 29, 2018, 9:37:21 AM6/29/18
to web...@googlegroups.com
Am using nlp, regex. I just want to capture that error. 

On Fri, 29 Jun 2018, 15:41 Leonel Câmara <leonel...@gmail.com> wrote:
If you want to do that right you need to do natural language processing e.g. using python nltk.

--

Leonel Câmara

unread,
Jun 29, 2018, 10:03:06 AM6/29/18
to web2py-users
Well if you just want to capture the error you simply need to put stuff inside a try/except.

try:
    # your stuff
except TypeError:
    # other stuff you do when the error happens

Maurice Waka

unread,
Jun 29, 2018, 12:33:32 PM6/29/18
to web...@googlegroups.com
Thanks for the help.
Be blessed 

On Fri, 29 Jun 2018, 17:03 Leonel Câmara <leonel...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages