Clearly, your list of x attributes is not homogeneous; at least one of the attributes you list there is a function, while at least one other is a dict.
python - AttributeError: 'function' object has no attribute 'value' error when reading the variables of a function - Stack Overflow
AttributeError: 'function' object has no attribute '__name__'
Getting an error during inference fairly simple model: 'function' object has no attribute 'items'
Don't know how to fix AttributeError: 'function' object has no attribute 'pk' when trying to create new users from registration form
Videos
morseCodeM={".-":"A",
"-...":"B",
"-.-.":"C",
"-..":"D",
".":"E",
"..-.":"F",
"--.":"G",
"....":"H",
"..":"I",
".---":"J",
"-.-":"K",
".-..":"L",
"--":"M",
"-.":"N",
"---":"O",
".--.":"P",
"--.-":"Q",
".-.":"R",
"...":"S",
"-":"T",
"..-":"U",
"...-":"V",
".--":"W",
"-..-":"x",
"-.--":"Y",
"--..":"Z",
" / ":" "}
def morseToText(inp):
out=""
while(inp!=" "):
for i in morseCodeM:
if(inp.find(i)!=-1): <-----------------------
out=out+morseCodeM[i]
inp2=list(inp)
inp2[inp.find(i):inp.find(i)+(len(i)-1)]=""
inp="".join(inp2)
return outI honestly don't know whats wrong it just gives the error :"AttributeError: 'function' object has no attribute 'find'" on the line with the arrow .
edit: the code is about converting morse code to text
If you want to use Object.Attribute, you should declare a class instead of a function.
class A:
def __init__(self):
self.value = [1, 2, 3, 4, 5]
a = A()
print('Val:', a.value)
# Returns [1, 2, 3, 4, 5]
Since the attribute a.value is created when a is executed, it will (obviously!) not exist until a has executed. You are calling a in a thread. When threads are involved, there are very few certainties about what gets executed in what order. In particular, there is no guarantee that, when your program reaches the line after the Thread.start() call, the thread has even started running, let alone finished! Furthermore, even if it has finished, there is no guarantee that any actions performed by it are visible to the main thread. To be sure of this, you have to use some kind of synchronization mechanism, or join() the thread from the main thread.