user_file = open('D:\Develop\Python27\user_info.txt','r') lines = user_file.readlines() for line in lines: username = line.split(',')[0] password = line.split(',')[1] print username,password
输出为:
zhangsan 123
lisi 456
wangwu 789
注:若txt中含中文,txt编码格式应为UTF-8