从元组中删除信息
我知道不能编辑Tupules,但我计划创建一个新的。我正在从文件中导入信息,然后删除名字,姓氏和出生年份。我只是不知道如何编辑它,以便我可以将所有内容删除以获取每个元素。对不起,如果这令人困惑!
这是我的代码!
#Open file for employee information
employee_info_file=open('employees.txt','r')
#Loop for all employees
for line in employee_info_file:
#Read info and convert to tupule
employee_info=employee_info_file.readline()
employee_tupule=(employee_info)
#Designate first name, last name, and year born
first_name=
last_name=
year_born=
像这样的Employee_tupule打印
Mark,Acrobello,8/12/1988
,但每行的名称,姓氏和DOB的长度都不同。租赁帮助!谢谢!
I know tupules can't be edited but I'm planning on creating a new one. I'm importing information from a file and then cutting out the first name, last name, and year of birth. I just don't know how to edit it so I can cut out everything past the comma to get each element. Sorry if this is confusing!
Here's my code!
#Open file for employee information
employee_info_file=open('employees.txt','r')
#Loop for all employees
for line in employee_info_file:
#Read info and convert to tupule
employee_info=employee_info_file.readline()
employee_tupule=(employee_info)
#Designate first name, last name, and year born
first_name=
last_name=
year_born=
employee_tupule prints like this
Mark,Acrobello,8/12/1988
But each line has a different length for first name, last name, and DOB. lease help! thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望我正确理解了你..
您正在读取一个文件,在每一行中,都有一个员工,其数据格式如下:“Mark,Acrobello,8/12/1988”,并且您想要一个包含 3 个元素的元组:姓名、姓氏和日期。
您可以通过对字符串使用 split 方法来实现这
一点:
I hope I understood you correctly..
you are reading a file and in each line, there is an employee with some data in this format: "Mark,Acrobello,8/12/1988" and you want to have a tuple that has 3 elements, name, last name, and the date.
you can achieve that by using the split method on the string:
prints: