仍未解决的部分

我正在尝试转换csv文件中存储的数据'存储.txt'以使我可以更有效地使用它很容易。就像目前,我的文件存储中的项目如下:Leroy,55349234,ok@gmail.com

Satish,231355,no@hi.com

Krut,6969,69@96.com

我想得到上述数据,并将其列为一个列表,如(在选项4中):

^{pr2}$

我试图把它转换成list,所以我想做的基本上是当用户想知道某个特定成员的详细信息时,比如说“Satish”,我希望代码能够在整个文件中找到“Satish”的名称,然后将整行作为一个列表,例如:

['Satish','231355','没有@hi.com']

所以现在用户可以输入如果他们想知道他的名字,联系方式或电子邮件id.说用户只想知道他的电子邮件,所以我要做的就是

打印元素[2]。在

已解决

如Jura所建议。

现在,来到我的选择3,(这里是代码):#a=(raw_input("Enter the staff's name: ")).capitalize()

a=(raw_input("Enter the staff's name: ")).capitalize()

with open('store.txt', 'r') as store:

reader = csv.reader(store)

for row in reader:

if row[0]==a:

print row

continue

else:

print "No staff with name %s is found in the database,please try again."%a

break

当我运行程序并选择3时,我得到两个错误:

1) 如果我把名字写为“Leroy”,我会得到:Database

1)Register people

2)View People registered

3)Staff Details

Enter your choice over here: 3

Enter the staff's name: leroy

['Leroy', '55349234', 'ok@gmail.com']

No staff with name Leroy is found in the database,please try again

但这是不应该发生的,因为档案里已经有了“勒罗伊”存储.txt,那么为什么python也运行else语句并打印“在数据库中找不到名为Leroy的员工,请重试”。

2) 现在当我在“Krut”中tpye时,它会说“在数据库中找不到名为Krut的员工,请再试一次。”存储.txt'

. 在

以下是我的源代码:import csv

print "Database"

print "1)Register people"

print "2)View People registered"

print "3)Staff Details"

choice=input("Enter your choice over here: ")

#This part takes the input from the user and then stores it in 'store.txt'

if choice==1:

a=input("Enter how many people to register: ")

for i in range(0,a) :

a=(raw_input("Enter the name: ")).capitalize()

b=input("Enter contact number: ")

c=raw_input("Enter the email ID: ")

d=raw_input("Enter your address: ")

with open ('store.txt','a') as store:

storeWriter=csv.writer(store)

storeWriter.writerow([a,b,c])

store.close()

#This prints all the data in the file 'store.txt

if choice==2:

with open('store.txt', 'r') as store:

reader = csv.reader(store)

print"- - - - - - - - - - - - - - - - - - - - - - - - - - - - "

for row in reader:

print 'Name:- '+row[0]

print 'Phone Number:- '+row[1]

print 'Email ID:- '+row[2]

print"- - - - - - - - - - - - - - - - - - - - - - - - - - - - "

if choice==3:

#a=(raw_input("Enter the staff's name: ")).capitalize()

a=(raw_input("Enter the staff's name: ")).capitalize()

with open('store.txt', 'r') as store:

reader = csv.reader(store)

for row in reader:

if row[0]==a:

print row

continue

else:

print "No staff with name %s is found in the database,please try again."%a

break

if choice==4:

print "List"

'''

What this program does basically is that it checks the entered name(a).But then if i type the name 'Leroy' it not only prints the

first line but also prints "No staff with name Leroy is found in the database,please try again." which is not required.And now if i

eneter a as Krut, it prints "No staff with name %s is found in the database,please try again." even though there is a name Krut in the

field.How do i get this done (i.e Enter Krut and then it should print row of 'Krut' that is "Krut,5537590,froost1999@outlook.com"

Also next i want is that (in choice 4) if they eneter the name , it converts the file's(store.txt) data into a listSo basically what

i can do with that would be like print elemenet [0] for name, element[1] for contact number,element[2] for email ID etc.Like it should

make the first line of code that is "Leroy,55349234,ok@gmail.com" into a list form ['Leroy','55349234','ok@gmail.com']

so that when the user asks for the contact detail of the specific person i can just print list.(1) to get

their phone number.

'''

python将csv文件转换为列表_如何将csv文件数据转换成列表?相关推荐

  1. python pyc文件是啥_什么是.pyc文件

    Python是一门解释性语言,我就这样一直相信下去,直到发现了*.pyc文件的存在. 如果是解释型语言,那么生成的*.pyc文件是什么呢?c应该是compiled的缩写才对啊! 为了防止其他学习Pyt ...

  2. Java代码给csv文件加水印_如何给CSV数据包的图片批量加上水印

    批量加水印要用到加水印的工具了吧 一.发布产品的时候,你的图片传到网上去的时候,都有一个选项,是否要在图片上加水印,系统默认的都是加水印的,你只要不选否,都是加了的. 二.photoshop加水印 1 ...

  3. TF之TFOD-API:基于tensorflow框架利用TFOD-API脚本文件将YoloV3训练好的.ckpt模型文件转换为推理时采用的.pb文件

    TF之TFOD-API:基于tensorflow框架利用TFOD-API脚本文件将YoloV3训练好的.ckpt模型文件转换为推理时采用的frozen_inference_graph.pb文件 目录 ...

  4. mysql workbench导入mdb_如何将MDB(Access)文件转换为MySQL(或纯SQL文件)?

    你想转换mdb到mysql(直接传输到mysql或mysql转储)? 尝试一个名为访问MySQL的软件. 访问MySQL是一个小程序,将Microsoft Access数据库转换为MySQL. 向导界 ...

  5. epub文件打开乱码_什么是EPUB文件(以及如何打开一个文件)?

    epub文件打开乱码 A file with the .epub file extension is a popular file format used for storing eBooks and ...

  6. 怎么更改exe文件的图标_如何修改EXE文件的图标

    怎么更改exe文件的图标 Let's face it: some apps have really ugly icons. Sure, you could always create a shortc ...

  7. 使用MATLAB 将EASE-Grid 2.0投影坐标系下 的NC文件转换为相同坐标系下的geotiff文件

    目录 以SMOS L3 土壤水分产品数据为例 EASE-Grid2.0 不同分辨率网格参数 使用maprefcells创建对应网格参照系 转换后的tiff文件检查 以SMOS L3 土壤水分产品数据为 ...

  8. svn取消文件夹图标_如何去掉svn文件夹上面的符号

    如何去掉svn文件夹上面的符号 如何去掉svn文件夹上面的符号 第一步:建立一个名字叫做remove-svn-folders.reg的文本(先建立txt文件,然后粘贴内容后再修改文件名字),记得后缀要 ...

  9. wps将pdf扫描文件转换为可复制/搜索文字的文件

    如题 最近下载了一本扫描电子书,需要复制书里面的文字.不想一段一段文字识别.下面是将文件转换为可复制文字文件的方法. 此方法不改变排版和页面效果,复制的文字有一定的误差. 方法如下: wps 打开pd ...

  10. angularjs java 文件上传_学习使用AngularJS文件上传控件

    前段时间做项目遇到一个需求是上传文件,大概需要实现的样式是这样子的,见下图: 需要同时上传两个文件.并且规定文件格式和文件大小.因为前端框架使用angular,且不想因为一个上传功能又引入一个jque ...

最新文章

  1. jsp 环境配置记录
  2. Agent Job相关的系统表
  3. 【leetcode】762. 二进制表示中质数个计算置位
  4. 福州java培训哪里好_南京Java培训哪家好?
  5. tomcat无法访问MySQL_JSP在tomcat服务器下无法连接MySql问题解决方法
  6. c++中容器(STL)的共性与使用的时机
  7. 刚刚,SeetaFace版本升级!新增活体检测等功能
  8. delphi 选择文件夹目录_系统小技巧:不装软件 批处理为文件夹加锁
  9. 转 - Web新人(偏前端)应该怎样学习(个人观点,勿喷)
  10. GPS时间服务器在电力监控系统中的应用方案
  11. 复杂参数的基本使用方式
  12. CocosBuilder 完全攻略
  13. kali破解wifi密码
  14. “萝卜快跑”,“快”不起来——百度Robotaxi试乘体验
  15. [360] 《如何保持电力接触网与受电弓亲密接触》
  16. 新手入门电脑和S7 200Smart PLC 的自由口通信
  17. 【信号去噪】基于小波阈值实现心电信号去噪附matlab代码
  18. 微信小程序进度条样式_详解微信小程序——自定义圆形进度条
  19. Linux中samba配置和windows映射Linux驱动盘
  20. Flink流批一体从入门到入土(源码)

热门文章

  1. python猜数字输入字母报错_Python 3.7.0 笔记(不完整)
  2. FusionCompute存储虚拟化
  3. 苹果cms的全解析(第一节大体阐述)
  4. 如何在通达信软件上随意画图_[原创]谁能修改下画图工具啊?
  5. Hadoop生态圈(六)- HDFS NAMENODE 安全模式
  6. 昆仑通态MCGS与西门子V20变频器通讯程序 西门子变频器通讯
  7. TIN---delaunay构网
  8. mysql ver 14.14 distrib 5.5.49_MySQL简介及安装 mysql Ver 14.14 Distrib 5.7.28
  9. Linux 一键测试、测速脚本更新,增加TikTok和iQIYI Intl解锁区域检测
  10. android studio 创建 jniLibs文件夹用于放置jar包和os文件