I get the error saying "TypeError: expected string or bytes-like object" how do I fix this?
I get the error saying "TypeError: expected string or bytes-like object" how do I fix this?
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
# above is where I get the error from
load_ws[i+1,4] = str(datatocopy)
else:
continue
以上是我的部分代码。我从 datatocopy = final_keys[word]
收到错误说 TypeError: expected string or bytes-like object.
。有帮助吗?
我检查了你的代码,你提到的抛出错误的那一行工作正常。
这是我试过的:-
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
print("Values : ", datatocopy)
# above is where I get the error from
# load_ws[i+1,4] = str(datatocopy)
else:
continue
这是输出:
Values : a,b,c,d,b
Values : a,b,c,d,b
Values : s,q,d,f,d,s,d
Values : s,q,d,f,d,s,d
Values : a,q,v,d,s,
Values : a,q,v,d,s,
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
# above is where I get the error from
load_ws[i+1,4] = str(datatocopy)
else:
continue
以上是我的部分代码。我从 datatocopy = final_keys[word]
收到错误说 TypeError: expected string or bytes-like object.
。有帮助吗?
我检查了你的代码,你提到的抛出错误的那一行工作正常。 这是我试过的:-
words = ['apple','bear','cinema']
dataset2 = ['apple','apple','bear','bear','pooh','cinema','cinema']
final_keys = {'apple':'a,b,c,d,b','bear':'s,q,d,f,d,s,d', 'cinema':'a,q,v,d,s,'}
for word in words:
for i in range(len(dataset2)):
if word == str(dataset2[i]):
datatocopy = final_keys[word]
print("Values : ", datatocopy)
# above is where I get the error from
# load_ws[i+1,4] = str(datatocopy)
else:
continue
这是输出:
Values : a,b,c,d,b
Values : a,b,c,d,b
Values : s,q,d,f,d,s,d
Values : s,q,d,f,d,s,d
Values : a,q,v,d,s,
Values : a,q,v,d,s,