随笔分类 -  Python

摘要:1 # FileName: cardbook.py 2 3 # this program helps u manage your card book. 4 # it has 6 functions: 5 # 1. add a record 4. print the cardbook 6 # 2. del a record 5. save the cardbook 7 # 3. search a record 6. exit... 8 9 # card book will be saved in c:\\p... 阅读全文
posted @ 2012-03-21 00:46 Alex_Monkey 阅读(524) 评论(0) 推荐(0) 编辑
摘要:Python标准库Python标准库是随Python附带安装的。这些模块可以解决大部分的问题。1.sys模块:包含系统对应的功能。使用sys.args即命令行参数一下代码类似cat功能,命令参数为“--version”或“-help”时,打印相关说明;为文件时,打印其内容。 1 # Filename: cat.py 2 import sys 3 def readfile(filename): 4 '''Print a file to the standard output.''' 5 f = file(filename) 6 while True 阅读全文
posted @ 2012-03-18 22:06 Alex_Monkey 阅读(712) 评论(0) 推荐(0) 编辑
摘要:面向对象类中的属性: 域和方法类的方法的第一个参数为self(类似于this指针),调用时无需写明__init__方法,在类的对象被建立时,马上运行。(类似于构造函数)def __init__(slef, name):__del__方法,(类似于析构函数)有两种类型的 域:类的变量和对象的变量(类似于c#中静态变量),是否有self来区分两者。python中所有类成员是公共的,方法是有效地。例外:双下划线为前缀的数据成员是私有的。继承: 1 # Filename: inherit.py 2 class SchoolMember: 3 "'Represents any scho 阅读全文
posted @ 2012-03-17 22:05 Alex_Monkey 阅读(295) 评论(0) 推荐(0) 编辑
摘要:一个归档的小程序。 1 # Filename: backup_ver3 2 import os 3 import time 4 #import sys 5 #reload(sys) 6 #sys.setdefaultencoding('utf8') 7 # 1. The files and directories to be backed up are specified in a list. 8 source = ['C:\\networkx.txt', 'c:\\backup\\'] 9 10 # 2. The backip must be 阅读全文
posted @ 2012-03-17 18:57 Alex_Monkey 阅读(320) 评论(0) 推荐(0) 编辑
摘要:python中有三种内部数据结构:列表、元组、字典(using_list.py,using_tuple.py, using——dict.py)list:列表。shoplist = ['apple', 'mango', 'carrot', 'banana'] 方法,尾部添加shoplist.append('rice'),排序shoplist.sort(),删除del shoplist[i] 1 # Filename: using_list.py 2 # This is my shopping list 3 shopl 阅读全文
posted @ 2012-03-17 14:05 Alex_Monkey 阅读(1593) 评论(0) 推荐(0) 编辑
摘要:python中有四种类型的数:整形 长整型 浮点数 复数python用缩进来标示语句块字符串下一行继续用 \"This is the first sentence.\This is the second sentence."自然字符串即非转义字符串,加前缀r或Rr"hello, world"unicode编码加前缀u或Uu"This is a unicode string"级联字符串'What\'s' 'your name?' = "What's your name?" 阅读全文
posted @ 2012-03-17 00:54 Alex_Monkey 阅读(381) 评论(0) 推荐(0) 编辑