Fehlermeldung Python Jupyter Programm
Verfasst: Donnerstag 9. Juni 2016, 08:25
Hallo,
in folgendem Programm erhalte ich eine Fehlermeldung, wenn ich button1 oder button2 aktiviere.
Die Fehlermeldung lautet: TypeError Traceback (most recent call last)
TypeError: 'NoneType' object is not callable
auch wird meine Textarea zweimal ausgegeben, von Beginn an. Das dürfte nicht sein, weil anfangs die init_vectors Funktion nur einmal aktiviert wird. Irgendwo wird ein nicht typisiertes Objekt übergeben, aber ich weiß nicht wo.
in folgendem Programm erhalte ich eine Fehlermeldung, wenn ich button1 oder button2 aktiviere.
Code: Alles auswählen
from sympy.matrices import *
from sympy.printing import *
from IPython.display import display, HTML, Math, Latex, clear_output
from ipywidgets import widgets
from random import randint
from sympy import *
from builtins import str
from copy import deepcopy
import numpy as np
text1 = widgets.Text()
button1 = widgets.Button(description="Auswerten")
button2 = widgets.Button(description="Neue Aufgabe")
x=[]
#x[0] = Matrix()
#x[1] = Matrix()
#x[2] = Matrix()
latexWidget = widgets.Latex()
a_text=""
taskWidget = widgets.HTML()
anzahl_matrizen=0
mhbox1 = widgets.HBox((taskWidget, latexWidget))
mhbox2 = widgets.HBox((button1, button2))
def init_vectors(b, matrix_1, anzahl_1, matrix_2):
w=widgets.Textarea(
description='Matrix',
value = str(matrix_1),
)
display(w)
global x, anzahl_matrizen, text1
anzahl_matrizen=0;
for u in range(anzahl_1):
copy_matrix=deepcopy(matrix_1)
x.append(copy_matrix)
if isinstance(matrix_2,Matrix):
x.append(matrix_2)
for u in range(anzahl_1):
anzahl_matrizen=anzahl_matrizen+1
for i in range(matrix_1.shape[1]):
for j in range(matrix_1.shape[0]):
x[u][j,i]=randint(-10,10)
#w=widgets.Textarea(
#description='Matrix',
#value = str(x[0]),
#)
#display(w)
#w=widgets.Textarea(
#description='Matrix',
#value = str(x[1]),
#)
#display(w)
if isinstance(matrix_2,Matrix):
anzahl_matrizen+=1
for i in range(matrix_2.shape[1]):
for j in range(matrix_2.shape[0]):
x[anzahl_1][j,i]=randint(-10,10)
#w=widgets.Textarea(
#description='Matrix',
#value = str(x[anzahl_1]),
#)
#display(w)
text1.value = ""
display_task()
#w=widgets.Textarea(
#description='Matrix',
#value = str(anzahl_matrizen),
#)
#display(w)
def display_task():
global x, anzahl_matrizen, latexWidget
a=[]
#w=widgets.Textarea(
#description='Matrix',
#value = str(anzahl_matrizen),
#)
#display(w)
clear_output()
for i in range(anzahl_matrizen):
b=latex(x[i])
b=b.replace("left[", "left(")
b=b.replace("right]", "right)")
a.append(b)
str1="$\langle"
for i in range(anzahl_matrizen):
str1=str1+a[i]+", "
str1 += "\\rangle$"
latexWidget.value = str1
def evaluate(b, aufgabe):
global x,text1
u_wert=1
if aufgabe=="Lineare Unabhängigkeit":
n_matrix_gesamt=np.matrix([x[0],x[1],x[2]]).astype(float)
#w=widgets.Textarea(
#description='Matrix',
#value = str(n_matrix_gesamt),
#)
#display(w)
u_wert=1
if np.linalg.det(n_matrix_gesamt)==0:
u_wert=2
else:
u_wert=1
#z = x.dot(y)
clear_output()
display_task()
#if "{0}".format(z) == text1.value:
#display(HTML("<b><font color='green'>Richtig</font></b>"))
#else:
#display(HTML("<b><font color='red'>Falsch</font></b>"))
if "{0}".format(u_wert) == text1.value:
display(HTML("<b><font color='green'>Richtig</font></b>"))
else:
display(HTML("<b><font color='red'>Falsch</font></b>"))
def exec_la_scalar(aufgabentext, matrix1, anzahl1, matrix2, aufgabe):
taskWidget.value = "<b>{0}</b>".format(aufgabentext)
init_vectors(button1, matrix1, anzahl1, matrix2)
button2.on_click(init_vectors(button1, matrix1, anzahl1, matrix2))
button1.on_click(evaluate(button1, aufgabe))
display(widgets.VBox((mhbox1, text1, mhbox2)))
TypeError: 'NoneType' object is not callable
auch wird meine Textarea zweimal ausgegeben, von Beginn an. Das dürfte nicht sein, weil anfangs die init_vectors Funktion nur einmal aktiviert wird. Irgendwo wird ein nicht typisiertes Objekt übergeben, aber ich weiß nicht wo.