我正在尝试制作一个程序,它从两个文本文件中逐行读取并存储您之前在Name_Input
中指定的行(在变量行和第2行中),然后删除任何不是字符串中的数字。
for line in Roster_Inputed:
if Name_Input in line:
line = re.sub('[^0-20]', '', line)
if line == "1":
print(Name_Input + " " + "should have " + line + " " + "ally.")
print " "
else:
print(Name_Input + " " + "should have " + line + " " + "allies.")
print " "
for line2 in Roster_Should_Have:
if Name_Input in line2:
line2 = re.sub('[^0-20]', '', line2)
if line2 == "1":
print(Name_Input + " " + "actually has " + line2 + " " + "ally.")
print " "
else:
print(Name_Input + " " + "actually has " + line2 + " " + "allies.")
print " "
代码从两个包含空格后面的名称和数字的文件中读取,然后继续比较它们以确定它输出给用户的内容:
if line == line2:
print "All good"
elif line != line2:
print "Check " + Name_Input + "'s " + "spies"
print " "
我需要做的是检查“line”的值是否大于“line2”但是我不能这样做,因为它们是包含数字的字符串。有没有办法暂时将它们转换为整数?