Attribute Error: 'list' object has no attribute 'lower' problem - list

I am writing code for AI chatbot in which I have to lemmatize words of data corpus
word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns]
but it gives error like
Traceback (most recent call last):
word_patterns = [lemmatizer.lemmatize(word.lower()) for word in word_patterns]
AttributeError: 'list' object has no attribute 'lower'
How do I solve it??
I have no idea to resolve it

Related

AttributeError: 'SolverStatus' object has no attribute 'key'

i got this error message when running an energy system optimization problem. Please any tips on how to resolve this?
Blockquote
"Traceback (most recent call last):
File "C:\Users\aadetunj\Desktop\oemof-examples-master\OSeEM-SN-main\scripting\scenarios\OSeEM-SN.py", line 318, in
m.solve("cbc")
File "C:\Users\aadetunj\Anaconda3\envs\virtualenv\lib\site-packages\oemof\solph\models.py", line 204, in solve
status = solver_results["Solver"][0]["Status"].key
AttributeError: 'SolverStatus' object has no attribute 'key'
Blockquote

Why isdigit is working but isdecimal is not for a simple age code

This is the part of code I am talking about:
while True:
print 'What is your age(only numeric):'
age = raw_input()
if age.isdigit():
break
print 'Please try again. We take only numeric value.'
When I replace isdigit with isdecimal, I get this error no matter what value i enter.
Traceback (most recent call last):
File "test.py", line 4, in <module>
if age.isdecimal():
AttributeError: 'str' object has no attribute 'isdecimal'
Although it runs fine with isdigit.
Also, when I replace raw_input with input, it give this error.
Traceback (most recent call last):
File "test.py", line 4, in <module>
if age.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'
Am I doing something wrong which I am not able to catch? I am new to python and did my research about isdigit, is decimal, input and raw_input before putting down question here. It may be very minute error but I am not sure what is it.
For the first part:
In Python 2, isdecimal is a method of the unicode class, not of str (i.e. bytes). Hence:
>>> '3.2'.isdecimal()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'isdecimal'
>>> u'3.2'.isdecimal()
For the second part, input tries to guess what kind of input it gets, and will properly cast "1" into an int, while raw_input will always return the raw string. Since isdigit is a method defined in the str class, you get the error.

Python calling documentation of defined function

I am a newbie to python. Just try to get the comments defined in function using doc but getting the error.
Here's my code:
def nam(i):
"""passing the name to
a function"""
print('hello '+i+' good mornin')
And here's the error:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
print(nam._doc_)
AttributeError: 'function' object has no attribute '_doc_'
Replace _doc_ (single underline on each side) with __doc__ (double underlines)
To illustrate, let's define your function and display the documentation:
>>> def nam(i):
... """passing the name to
... a function"""
... print('hello '+i+' good mornin')
...
>>> nam.__doc__
'passing the name to\n a function'
The method above works. The method below, however, fails:
>>> nam._doc_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '_doc_'
The reason is that __doc__ needs two underline characters on each side, not just one.
Documentation
From the python online documentation:
docstring A string literal which appears as the first expression
in a class, function or module. While ignored when the suite is
executed, it is recognized by the compiler and put into the __doc__
attribute of the enclosing class, function or module. Since it is
available via introspection, it is the canonical place for
documentation of the object.

python3 'Nontype object' is not subscriptable

How can I solve this problem?
def median(lst):
lst_s=lst.sort()
k=len(lst)
if k%2==0:
return ((lst_s[k/2]+lst_s[k/2-1])/2)
elif k%2==1:
return (lst_s[k/2-1/2])
res = median([1,2,3,7,6,5])
print('median:',res)
when I run this, it says
Traceback (most recent call last):
File "E:\lab5_p4_2015123176.py", line 13, in <module>
res = median([1,2,3,7,6,5])
File "E:\lab5_p4_2015123176.py", line 7, in median
return ((lst_s[k/2]+lst_s[k/2-1])/2)
TypeError: 'NoneType' object is not subscriptable
The problem is that list.sort() sorts the items of the list in place thus returns None. In your median function you need to replace lst_s = lst.sort() by lst_s = sorted(lst) if you don't want to modify element order in the original list.

P4PYTHON : 'str' object has no attribute '_description'

from P4 import P4, P4Exception
p4 = P4()
p4.connect()
change = p4.fetch_change()
change._description = "My changelist\nSubmitted from P4Python\n"
Error: Traceback (most recent call last):
File "", line 1, in
AttributeError: 'str' object has no attribute '_description'
how can i fix this please ?
No Problem, I fixed it.I was using an older version of P4PYTHON module