如何检查包含字符串的变量是否等效于特定关键字



im试图检查csv文件中的一行是否有";"训练"PublicTest";,或";PrivateTest;(每一行都被归类为这三行中的一行,但即使用法是"训练"一词,程序也会将其识别为不同的单词,我能做些什么来解决这个问题?


training_data = []
test_data = []
train_images = []
train_labels = []
test_images = []
test_labels = []
def format_data(path):
for row in open(path):
idx = 0
with open(path) as d:
emotion, image, usage = d.readlines()[idx + 1].split(",")
if usage is "Training":
train_labels.append(int(emotion))
imageArr = []
imageArr.append(image)
train_images.append(imageArr)
print(train_images)
elif usage is "PublicTest" or usage is "PrivateTest":
test_labels.append(int(emotion))
imageArr = []
imageArr.append(image)
test_images.append(imageArr)
print(test_images)
idx += 1

print("This row has been iterated over!")
# print(row)

# add any more formatting
# train_images/255.0
# test_images/255.0

def load_data():
return train_images, train_labels, test_images, test_labels

format_data(path)```

请在测试相等性时始终使用==。因此,在您的情况下,请尝试使用usage == "Training"而不是usage is "Training"

以下是关于这个主题的更多内容:=="以及";是"?";?。

相关内容

  • 没有找到相关文章

最新更新