python使用CSV实现电话本

初学者在Python学习过程中,通过一个实例程序了解如何利用CSV模块创建和管理电话本联系人信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开始学习Python,看了一道程序 http://www.oschina.net/code/snippet_230735_8468, 在此基础上修改了一下,

#!/bin/python
# coding:utf-8

import time
import csv

class TelBook:

    def __init__(self, filename):

        self._filename = filename


        """print title into file"""
        csvfile = file(self._filename, "wb")
        writer = csv.writer(csvfile)
        title = ["NAME", "TEL", "TIME"]
        writer.writerow(title)
        csvfile.close()

    def addPerson(self):

        """Add a new person information"""
        person = raw_input("Enter the person\'s name:")
        tel = raw_input("Enter the person\'s tel:")
        update = time.strftime("%Y-%m-%d %H:%m:%S")

        writer = csv.writer(file(self._filename, "ab"))
        writer.writerow([person, tel, update])

    def findPerson(self, personname):

        """find a person's information and print to terminal"""
        csvfile = file(self._filename, "rb")
        reader = csv.reader
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值