I was wondering what the number following the argument stands for (In the error message; the number is 1).
I am updating PsychoPy, and it showed the error message. I have searched for a while, but I did not find any explanation about it.
def onCancel(self, event):
self.app.updater = None
self.Close()
def onFileBrowse(self, event):
self.filename = event.GetString()
def onInstall(self, event):
if self.currentSelection == self.useLatestBtn:
info = self.doAutoInstall()
else:
info = self.installZipFile(self.filename)
self.statusMessage.SetLabel(info)
self.Fit()
Traceback (most recent call last):
File "C:\Program Files (x86)\PsychoPy3\lib\site-
packages\psychopy\app\connections\updates.py", line 404, in onInstall
self.statusMessage.SetLabel(info)
TypeError: Control.SetLabel(): argument 1 has unexpected type 'int'
As #TomKarzes points out in the comments, it's just plain English: argument 1 is referring to the first argument. argument 2 would refer to the second argument and so on.
Related
I am making a small calculator on Python3 using tkinter. In a section, I encountered
TypeError: 'NoneType' object is not callable
This is the section where I called the function:
def key_in(event):
if (event.keysym == 'Return'):
calculate()
elif (event.keysym == 'BackSpace'):
delete() # or clear()
# elif and else statements
I did not encounter any error in calculate but I get this TypeError in delete and clear
# ERROR (TypeError)
def delete():
"""Responsive function to delete the last entered character"""
global _expression, _equation # _expression = '<expression>', _equation = tkinter.StringVar()
try:
if (_expression[-1] != ' '):
_expression = _expression[0:-1:1]
else:
_expression = _expression[0:-3:1]
except IndexError:
pass
_equation.set(_expression)
# ERROR (TypeError)
def clear():
"""Function to clear the whole *_expression*"""
global _expression, _equation
_expression = ''
_equation.set(_expression)
# NO ERROR
def calculate():
"""Enters the calculated value of the expression
to the text box while handling errors
"""
global _expression, _equation
try:
try:
# Function `evaluate` will convert and calculate the `_expression` into a python
# understandable code and function `str` will convert the result into string
_expression = str(evaluate(_expression))
_equation.set(_expression)
except ZeroDivisionError:
_equation.set('∞')
_expression = ""
except:
_equation.set("ERROR")
_expression = ""
How can I solve this?
Actual error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\SpiderMan\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "G:\Python Programs\Calculator.py", line 489, in key_in
delete()
TypeError: 'NoneType' object is not callable
I'm learning python and gtk and so trying to using cairo to draw a rectangle in the screen with the mouse (I just managed to draw a rectangle without mouse).
However something strange is happening since I'm receiving more arguments than what I'm passing. How is that possible?
draw_rectangle - method definition:
def draw_rectangle (self, widget, start_x_cood, start_y_cood, ending_x_cood, ending_y_cood):
print ("draw_retangle")
cr = cairo.Context ()
cr.set_source_rgba(1, 1, 1, 1)
cr.rectangle(start_x_cood, start_y_cood, ending_x_cood, ending_y_cood)
cr.fill()
Method that calls draw_rectangle:
def on_motion_notify_event (self, widget, event):
print("on_motion_notify_event")
if event.is_hint:
x, y, state = event.window.get_pointer()
else:
x = event.x
y = event.y
state = event.state
if self.firstClick :
self.ending_x_cood = x
self.ending_y_cood = y
self.draw_rectangle(self, widget, self.start_x_cood, self.start_y_cood, self.ending_x_cood, self.ending_y_cood)
return True
This is giving me the following error:
on_motion_notify_event
Traceback (most recent call last):
File "gui2.py", line 56, in on_motion_notify_event
self.draw_rectangle(self, widget, self.start_x_cood, self.start_y_cood, self.ending_x_cood, self.ending_y_cood)
TypeError: draw_rectangle() takes exactly 6 arguments (7 given)
on_motion_notify_event
Traceback (most recent call last):
File "gui2.py", line 56, in on_motion_notify_event
self.draw_rectangle(self, widget, self.start_x_cood, self.start_y_cood, self.ending_x_cood, self.ending_y_cood)
TypeError: draw_rectangle() takes exactly 6 arguments (7 given)
Where is that 7th argument coming from?
My searches are leading me to *args and **kwargs but it's not making much sense.
I've uploaded a runnable version of the code here
Python passes self to instance methods for you, so:
self.draw_rectangle(self, widget, self.start_x_cood, self.start_y_cood, self.ending_x_cood, self.ending_y_cood)
actually is passing self twice. You want:
self.draw_rectangle(widget, self.start_x_cood, self.start_y_cood, self.ending_x_cood, self.ending_y_cood)
I wrote a code which is going to store occurrences of words from a text file and store it to a dictionary:
class callDict(object):
def __init__(self):
self.invertedIndex = {}
then I write a method
def invertedIndex(self):
print self.invertedIndex.items()
and here is how I am calling:
if __name__ == "__main__":
c = callDict()
c.invertedIndex()
But it gives me the error:
Traceback (most recent call last):
File "E\Project\xyz.py", line 56, in <module>
c.invertedIndex()
TypeError: 'dict' object is not callable
How can I resolve this?
You are defining a method and an instance variable in your code, both with the same name. This will result in a name clash and hence the error.
Change the name of one or the other to resolve this.
So for example, this code should work for you:
class CallDict(object):
def __init__(self):
self.inverted_index = {}
def get_inverted_index_items(self):
print self.inverted_index.items()
And check it using:
>>> c = CallDict()
>>> c.get_inverted_index_items()
[]
Also check out ozgur's answer for doing this using #property decorator.
In addition to mu's answer,
#property
def invertedIndexItems(self):
print self.invertedIndex.items()
then here is how you'll cal it:
if __name__ == "__main__":
c = callDict()
print c.invertedIndexItems
Methods are attributes in Python, so you can't share the same name between them. Rename one of them.
This is what I have so far
vdcm = (self.register(self.checkForInt), '%S')
roundsNumTB = Entry(self, validate = 'key', validatecommand = vdcm)
Then the checkForInt() function is defined as so
def checkForInt(self, S):
return (S.isDigit())
The entry box is meant to take an even number, and a number only; not characters. If a character is inputted, it is rejected. This will only work once though. If a character is inputted, the next keystroke which is an input is not rejected.
If someone could tell me how to make it permanently check to make sure the string is a digit, and an even one at that, it would be appreciated.
This is the error message I get if it's any help
Exception in Tkinter callback
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1470, in __call__
return self.func(*args)
File "[py directory]", line 101, in checkForInt
return (S.isDigit())
AttributeError: 'str' object has no attribute 'isDigit'
I think the function call is isdigit() and not isDigit(), note the capitalization difference. If you want to test that the input is an integer and is even you would have to first convert the string using int() and test:
def checkForEvenInt(self, S):
if S.isdigit():
if int(S) % 2 is 0:
return True
return False
Keep in mind that Python is quite case-sensitive, including functions. For example, here's an iPython session:
In [1]: def my_func(): return True
In [2]: my_func()
Out[2]: True
In [3]: my_Func()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-25-ac6a0a3aba88> in <module>()
----> 1 my_Func()
NameError: name 'my_Func' is not defined
i'm having a problem in my unit tests, i don't know why, I'm gotting the following stack:
Traceback (most recent call last):
File "novaapiclient_tests.py", line 11, in test_create_server
nova = novaapiclient.NovaAPIClient()
TypeError: __init__() takes exactly 2 arguments (1 given)
follow my test code:
class TestFunction(unittest.TestCase):
def setUp(self):
self.nova = novaapiclient.NovaAPIClient()
def test_create_server(self):
self.setUp()
lsbf = self.nova.lst_of_servers(self.nova.listServers())
image = "3f9e6696-2ed2-4e06-ae16-c828062addbe"
flavor = "m1.tiny"
name = "testing_unit"
self.nova.createServer(image, flavor, name)
time.sleep(60)
lsaf = self.nova.lst_of_servers(self.nova.listServers())
if(len(lsbf) < len(lsaf)):
assertTrue(True)
else:
assertTrue(False)
def delete_server(self):
self.setUp()
serv_id = "13e0c3de-d736-47ec-bc22-3a794aa3e2a9"
self.nova.deleteServer(serv_id)
ls = self.nova.lst_of_servers(self.nova.listServers())
j = 0
fin = False
while(j < 3 and not fin):
time.sleep(75)
for i in range(len(ls)):
if(serv_id == str(ls[i])):
assertTrue(False)
break
assertTrue(True)
fin = True
break
j += 1
I tried to create a init method and cut the "self" in the methods, but i continues printing the error.
The novaapiclient.NovaAPIClient constructor needs to receive an argument, but you aren't passing any.
In this question of yours you did pass an argument to novaapiclient.NovaAPIClient, so I assume you need to do something similar.