我有一个包含此信息的文件(记事本): (如果有人可以解决它,请编辑)
Jackson,Samantha,2 Heather Row,Basingstoke,RG21 3SD,01256 135434,23/04/1973,sam.jackson@hotmail.com
Vickers,Jonathan,18 Saville Gardens,Reading,RG3 5FH,01196 678254,04/02/1965,the_man@btinternet.com
Morris,Sally,The Old Lodge, Hook,RG23 5RD,01256 728443,19/02/1975,smorris@fgh.co.uk
Cobbly,Harry,345 The High Street,Guildford,GU2 4KJ,01458 288763,30/03/1960,harry.cobbly@somewhere.org.uk
Khan,Jasmine,36 Hever Avenue,Edenbridge,TN34 4FG,01569 276524,28/02/1980,jas.khan@hotmail.com
Vickers,Harriet,45 Sage Gardens,Brighton,BN3 2FG,01675 662554,04/04/1968,harriet.vickers@btinternet.com
我如何向用户提问?EG:你想搜索什么,他们说名字,然后我说输入一个名字,我怎么能从csv文件中提取这些信息并打印出来?
答案 0 :(得分:3)
看看那个
#!/usr/bin/python
#coding=utf-8
import operator
import csv
reader = csv.reader(open("database.csv"), delimiter=",")
分隔后,使用for循环输入您需要的变量!