zoukankan      html  css  js  c++  java
  • python初体验

    一个同事要离职了,她把python相关的东西交给了我。祝她好运

    # -*- coding: utf-8 -*-
    """
    Created on Tue Aug 23 16:22:05 2011
    一个通讯录程序
    一个同事要离职了,她把python相关的东西交给了我。祝她好运
    就这么个小东西,居然写了快两个点儿,留个纪念。
    @author: Joey
    """
    import os

    class Info:
    def __init__(self,name,address,phone):
    self.name
    = name
    self.address
    = address
    self.phone
    = phone

    class InfoAccess:
    def save(self,info):
    f
    = file('address.txt', 'a') # open for 'a'ppend
    f.write(info.name.join('\r\n'))
    f.write(info.address.join(
    '\r\n'))
    f.write(info.phone.join(
    '\r\n'))
    f.close()
    # close the file

    def getAll(self):
    list
    = []
    f
    = file('address.txt')
    while True:
    line
    = f.readline()
    if len(line) == 0:
    break
    else:
    name
    = line;
    address
    = f.readline();
    phone
    = f.readline();
    info
    = Info(name,address,phone)
    list.append(info)
    return list

    infoAccess
    = InfoAccess()
    while(1):
    os.system(
    "cls")
    print('--------------------address---------------------')
    print(' a: new address')
    print(' b: view address list')
    print(' c: exit')
    inputStr
    = (raw_input())
    if inputStr == 'a':
    print('input name:')
    name
    = raw_input()
    print('input address:')
    address
    = raw_input()
    print('intput phone:')
    phone
    = raw_input()
    info
    = Info(name, address, phone)
    infoAccess.save(info)
    elif inputStr == 'b':
    list
    = infoAccess.getAll()
    for element in list:
    print('------------------------')
    print('name:')
    print(element.name)
    print('address')
    print(element.address)
    print('phone:')
    print(element.phone)
    print("press anykey to continue")
    raw_input()

    elif inputStr == 'c':
    break
    else:
    print('error')

      

  • 相关阅读:
    [MS POST]Visual Studio Tips and Tricks
    Mono
    网络编程 socket编程
    Project Properties
    Review Error Handling
    [ILDASM Boxing]从进一步了解Struct和Class的不同学到的
    Steps to Bind VS solution to Source Control
    不已0开头的数字正则
    Jquery 解决移动端onclick事件300ms延迟问题
    毫秒转换日期
  • 原文地址:https://www.cnblogs.com/zzy0471/p/2151103.html
Copyright © 2011-2022 走看看