The error I'm getting is:
TypeError: 'str' object is not callable
I searched through some other questions, they all said that i redefined a function earlier in my code, but i could not find any occasion where I did this.
My code is:
firstElement = driver.find_elements_by_xpath('//*[#id="assessment-leaderboard"]/li[1]')
print(firstElement)
if len(firstElement) > 0:
print(firstElement[0].text())
else:
print('no data')
Probably, the issue is that .text is not a function but an attribute, so you might want to try
print(firstElement[0].text)
without ().
Related
I'am quite new to python and I am developing a passport scanner with a RaspberryPi and the passport eye module. In the end it prints outs the outcome of the scanned image. However, I also want to print an outcome if the scanner isn't able tot detect a MRZ code.
I tried some things but couldn't figure it out, here is a example in short:
mrz = read_mrz("test.jpg")
mrz_data = mrz.to_dict()
if mrz.to_dict == None:
print("Invalid document")
else:
print(mrz_data["names"])
Error in
mrz_data = mrz.to_dict() AttributeError: 'NoneType' object has no attribute 'to_dict'
EDIT: Is there a way to print when the error is 'NoneType' object has no attribute 'to_dict'
From the official docs -
The returned object (unless it is None, which means no ROI was detected) contains the fields extracted from the MRZ along with some metainformation
Looks like the image that you are using returns None. In line 2 when you call the to_dict() on None, it throws the exception 'NoneType' object has no attribute 'to_dict'
This can be fixed as follows
if mrz == None:
print("Invalid document")
else:
print(mrz.to_dict()["names"])
hope you are all in safe. I just wanted to get (20^5)-(1^5)/5(20-1)
myNum = ((20**5)-(1**5))/5(20-1)
print(myNum)
I took the TypeError: 'int' object is not callable
Then I changed it like;
print(((20**5)-(1**5))/5(20-1))
But I'm still getting same error. I checked the solutions but didn't understand what am I have to do.
Fix: ((20**5)-(1**5))/5/(20-1)
Error is that you can't omit multiply sign here: 5(20-1).
Interpreter considers you're trying to call function like f(...), but 5 is not a function, that's why you see error:
TypeError: 'int' object is not callable
^^^ ^^^^^^^^
5 (20-1)
After one month I decided to work on my app again. I open it and run it and I got this error: AttributeError: 'NoneType' object has no attribute 'find'. I remember that it worked fine, maybe there was a beautifulsoup update or the website (real estate) changed something? But no, the code is the same.
Here's the line that causes trouble according to the compiler:
propertyQuantity = soup.find("h1", {"class":"list-result-title"}).find("b", recursive = False).text
I can post the whole code if necessary. Do you notice something wrong with that line?
soup.find() returns None if it can't find the element you specify. You need to check for this before trying to invoke other methods on the result. So split it up into two statements:
h1 = soup.find("h1", {"class":"list-result-title"})
if h1:
property = find("b", recursive = False)
if property:
propertyQuantity = property.text
else:
// report problem finding `b`
else:
// report problem finding h1
I have been trying to check the type of an object and have been getting an ''int' object is not callable' error. As a test I have even removed the object completely and have replaced it with a constant, and am still getting the error.
This is pyqgis code but I don't think the GIS aspect is particularly relevant. I believe the issue is one of Python logic/syntax. This is the problem line:
QgsMessageLog.logMessage(type('1'), level=Qgis.Info)
I would have expected this to tell me that '1' is a string, but instead I get the error
TypeError: 'int' object is not callable
From what I know of this error I would have expected that this means that 'type' also exists as a property, but it doesn't as far as I am aware.
No, it means you've defined type somewhere earlier in your code. For example:
type = 1
print(type('1'))
You can resolve the issue by not shadowing built-in names.
I can't say I fully understand the script, because classes go beyond me as yet. Anyway, I've downloaded the py-omegle module from here . And I don't seem to be able to get it to run.
Hoping that I don't need to post the whole class including functions, the part in particular that I'm having trouble with pertains to urllib2 - so I guess It's not too specific an issue - the line that causes all of the issues is:
self.connector = urllib2.build_opener(processor),urllib2.HTTPHandler(debuglevel=1)
and it's not letting me:
#omegle.py
[ln33] self.connector.addheaders = [
[ln34] ('User-agent',user_agent)
[ln35] ]
# or
[ln98] self.id = self.connector.open(self.url+'start',data={}).read().strip('"')
Both return AttributeError:
AttributeError: 'tuple' object has no attribute 'addheaders'
# and further down
AttributeError: 'tuple' object has no attribute 'open'
Could someone please explain how to fix this? I'm sure it has something to do with the first line I posted. The entire source of the ONLY file in this module can be accessed here.
I think it's a case of misplaced parentheses.
The first line:
self.connector = urllib2.build_opener(processor),urllib2.HTTPHandler(debuglevel=1)
creates a tuple consisting of
urllib2.build_opener(processor)
and
urllib2.HTTPHandler(debuglevel=1)
And then assigns this tuple to self.connector.