Answer the question
In order to leave comments, you need to log in
Python How to get string from NoneType?
I attached a module to the program, I get p.POS from it
When outputting, it writes a string, for example 'NOUN', or gives None
I need to add my string to this value, but an error appears: TypeError: Can't convert 'NoneType' object to str implicitly
This class is .TypedGrammeme'>
QUESTION - How can I convert any returned value to a string?
list, str, ... doesn't help
Answer the question
In order to leave comments, you need to log in
def convert(obj):
try:
return str(obj)
except TypeError:
return ''
none_type=None
def convert_none_type(item):
if not item or item =='NOUN':
return ''
return item
print(convert_none_type(none_type)+'abc')
item_test = None
print((item_test if item_test else '') + ' add_str')
>>> add_str
item_test = None
print('%s_%s' % (item_test, ' add_str'))
>>> None_ add_str
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question