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')

      

  • 相关阅读:
    Ubuntu16.04+cuda9.0+matlab+opencv3.3+caffe服务器配置(问题汇总)
    numpy 实践记录
    qwe框架- CNN 实现
    qwe 简易深度框架
    深度拾遗(08)
    python 环境配置
    Robotframework Web自动化实战课程
    常用javascript代码片段集锦
    AJax跨域请求百度音乐接口数据展示页面
    JavaScript 经典实例收集整理
  • 原文地址:https://www.cnblogs.com/zzy0471/p/2151103.html
Copyright © 2011-2022 走看看