python
文章平均质量分 69
shougaogao2011
这个作者很懒,什么都没留下…
展开
-
python 小实例3 with 简化文件的读取的代码
rhel 将/bin/ls 拷贝一份并使新文件具有一样的查看功能。 第一步:文件的复制#!/usr/bin/env python #coding:utf8 srcfile = '/bin/ls' desfile = '/home/ls' with open(srcfile) as oldfile: with open(desfile,'w')as newfile:原创 2016-01-06 10:50:06 · 483 阅读 · 0 评论 -
python 编程小实例(2) 四则运算小游戏
从1 到100之间随机选取俩个整数,使用大的数字加上或者除以小的数值。 用户可以输入三次正确答案。三次不对则给出正确答案。 第一步:定义函数框架 def main(): while True: arithmetic() try: goon = raw_input('next(y/n)').strip()[0]原创 2016-01-04 21:51:12 · 2205 阅读 · 0 评论 -
python 小实例4 密码随机生成器
使用string模块、random模块 本函数定义了密码长度为8.用户可以自己设置密码的长度,修改num 数值即可 #!/usr/bin/env python #coding:utf8 '''reduce password randomly''' import random import string allcho = string.letters+string.digits de原创 2016-01-06 11:14:02 · 645 阅读 · 0 评论 -
python 小实例5 创建文件,并写入数据:要求不能与现存系统文件重名
#!/usr/bin/env python #coding:utf8 '''writing something to new file''' import os prompt='input filename :' ls=os.linesep mylist=[] def write(): while True: filename=raw_input(prompt)原创 2016-01-06 15:58:41 · 1068 阅读 · 0 评论 -
pyhton 实例6 格式化输出
#!/usr/bin/env python #coding:utf8 ''''format output''' begend = "+"+'*'*48+'+' mylist = [] while True: data = raw_input('input data(. > quit): ') if data == '.': break else:原创 2016-01-06 17:01:45 · 458 阅读 · 0 评论 -
python 实例7 为rhel添加系统用户与登录密码,并给root 发送邮件
#!/usr/bin/env python #coding:utf8 import os import passwd import string import sys content = 'username : ${user} \ userpassword :${password}' s=string.Template(content) def adduser(user原创 2016-01-07 14:51:13 · 696 阅读 · 0 评论 -
python 实例8 日常记账本小程序
实现收支的自动计算 能够查询每笔账款的消费详情 1、函数需要两个文件:一个类似钱包功能,存放钱;另一个用于记录每笔花销的用途 #!/usr/bin/env python import cPickle as p with open('wallet.data','w') as f: p.dump(10000,f) with open('record.txt','w') as f:原创 2016-01-11 17:57:12 · 9940 阅读 · 0 评论