在粘贴到变量之后,我很难从列表中找出插入问题
这是我正在读取的文件
Error (active) E1696 cannot open source file
Warning C26495 Variable 'Man::age' is uninitialized. Always initialize a member variable (type.6).
Warning C26495 Variable 'Student::age' is uninitialized. Always initialize a member variable (type.6).
Warning C26495 Variable 'Man::age' is uninitialized. Always initialize a member variable (type.6).
Warning C26495 Variable 'Student::age' is uninitialized. Always initialize a member variable (type.6).
Error C3867 'Teacher::getName': non-standard syntax; use '&' to create a pointer to member
Error C2664 'Man::Man(Man &&)': cannot convert argument 1 from 'int' to 'std::string'
这是功能
John:Yoko:1966
Brad:Anjolina:2005
Boonie:Clyde:1930
Clyde:Boonie:1930
Hillary:Bill:1971
Yoko:Jhon:1966
错误 回溯(最近通话最近): 文件“ C:/Users/omer/Desktop/pythonProjects/2016S1M1.py”,第28行,在 主要() 主文件“ C:/Users/omer/Desktop/pythonProjects/2016S1M1.py”,第21行 不匹配(“ airports.txt”) 文件“ C:/Users/omer/Desktop/pythonProjects/2016S1M1.py”,第13行,不匹配 two_couple = line.split(':') AttributeError:“ list”对象没有属性“ split”
答案 0 :(得分:1)
行已是列表,您不能将拆分功能应用于列表,请尝试以下操作:
def mismatched(file_name):
d={}
for line in open(file_name):
two_couple=line.rsplit()
couple1=two_couple[0]
couple2=two_couple[1]
print(two_couple)
#print(couple2)