摘要:
第十七章、 网络编程 1) FTP客户端 import ftplibimport osimport socket HOST = '127.0.0.1'DIRN = 'menus'FILE = 'hello.txt'USER = 'taojin'PASS = 'pass123' def main(): try: f = ftplib.FTP(HOST) f.login(user = USER, passwd = PASS) f.cwd(DIRN) f.retrbinary('RETR %s' % FI 阅读全文
posted @ 2011-10-13 12:20
方倍工作室
阅读(535)
评论(0)
推荐(0)
摘要:
第十六章、 正则表达式 1) 匹配多个表达式 记号 re1|re2 说明 匹配正则表达式re1或re2 举例 foo|bar 匹配 foo, bar 记号 {N} 说明 匹配前面出现的正则表达式N 举例 [0-9]{3} 匹配 2) 匹配单个/多个/范围内字符 记号 . 说明 匹配任何字符(换行符除外) 举例 b.b 匹配 b和b中间有一个任意字符bab, bcb, bbb 举例 .. (匹配任何两个字符) 匹配 xx, ab 记号 […] 说明 匹配字符组里面出现的任意一个字符 举例 b[aeiou]t 匹配3字符串 bat,bit,but,bet 举例 [ab][23][xy] 匹配3字符 阅读全文
posted @ 2011-10-13 12:18
方倍工作室
阅读(434)
评论(0)
推荐(0)
摘要:
第十五章、 结构布局 #!/usr/bin/env python #(1)起始行 "this is a module" #(2)模块文档 import sys #(3)模块导入 debug = True #(4)全局变量定义 class Fooclass(object): #(5)类定义 "Foo class" pass def test(): #(6)函数定义 "test function" foo = Fooclass() if... 阅读全文
posted @ 2011-10-13 12:16
方倍工作室
阅读(258)
评论(0)
推荐(0)
摘要:
第十四章、 地址薄作业#A Byte of Python#!/usr/bin/env pythonimport cPickleimport os #define the contacts file, listglobal file_contactsglobal list_contactsfile_contacts = 'AddressBook.txt'list_contacts = [] #delete the filetry: file_path = os.getcwd() + os.sep + file_contacts if os.path.isfile(file_pat 阅读全文
posted @ 2011-10-13 12:11
方倍工作室
阅读(363)
评论(0)
推荐(0)
摘要:
#$language = "VBScript"#$interface = "1.0"' This automatically generated script may need to be' edited in order to work correctly.Dim FTP_IP, FTP_User, FTP_Pass, FTP_PathFTP_IP = "10.11.44.1"'FTP_IP = "10.90.243.20"FTP_User = "mpsvr"FTP_P 阅读全文
posted @ 2011-10-13 12:10
方倍工作室
阅读(1374)
评论(0)
推荐(0)
摘要:
1: #$language = "VBScript" 2: #$interface = "1.0" 3: 4: ' This automatically generated script may need to be 5: ' edited in order to work correctly. 6: 7: Sub Main 8: 9: Dim cmd_show_chassis 10: Dim status_up, status_down 11: Dim time_minutes 12: 13: cmd_show_chassis = .. 阅读全文
posted @ 2011-10-13 12:10
方倍工作室
阅读(1295)
评论(0)
推荐(0)
摘要:
#$language = "VBScript"#$interface = "1.0"crt.Screen.Synchronous = True' This automatically generated script may need to be' edited in order to work correctly.Sub Main crt.Screen.WaitForString "Username: " crt.Screen.Send "root" & chr(13) crt.Scree 阅读全文
posted @ 2011-10-13 12:09
方倍工作室
阅读(2417)
评论(0)
推荐(0)
摘要:
第十三章、 特殊的方法 1) 特殊的方法 __init__(self,...) 这个方法在新建对象恰好要被返回使用之前被调用。 __del__(self) 恰好在对象要被删除之前调用。 __str__(self) 在我们对对象使用print语句或是使用str()的时候调用。 __lt__(self,other) 当使用 小于 运算符(<)的时候调用。类似地,对于所有的运算符(+,>等等)都有特殊的方法。 __getitem__(self,key) 使用x[key]索引操作符的时候调用。 __len__(self) 对序列对象使用内建的len()函数的时候调用。 2) exec和ev 阅读全文
posted @ 2011-10-13 12:08
方倍工作室
阅读(250)
评论(0)
推荐(0)
摘要:
第十二章、 标准库 See Python Manuals ? The Python Standard Library ? 1) sys模块 import sys if len(sys.argv) < 2: print 'No action specified.' sys.exit() if sys.argv[1].startswith('--'): option = sys.argv[1][2:] if option == 'version': print 'Version 1.2' elif option == ' 阅读全文
posted @ 2011-10-13 12:06
方倍工作室
阅读(361)
评论(0)
推荐(0)
摘要:
第十一章、 异常 1) try/except/else格式 try: s = raw_input('--> ')except EOFError: print 'Why did you do an EOF on me?'except: print 'Error occurred.'else:print 'Done' except参数说明: except: Catch all (or all other) exception types. except name: Catch a specific exception only. 阅读全文
posted @ 2011-10-13 11:58
方倍工作室
阅读(327)
评论(0)
推荐(0)
摘要:
第十章、 输入/输出 1) 文件poem = '''Programming is fun use Python!'''f = file('poem.txt', 'w') # open for 'w'ritingf.write(poem) # write text to filef.close() # close the file可以使用help(file)来了解详情。2) 储存器 pickle在文件中储存Python对象,cPickle(C语言,更快)import cPickle as pshopl 阅读全文
posted @ 2011-10-13 11:55
方倍工作室
阅读(286)
评论(0)
推荐(0)
摘要:
第九章、 类与面向对象 1) 类 基本类/超类/父类被导出类或子类继承。 Inheritance继承 Inheritance is based on attribute lookup in Python (in X.name expressions). Polymorphism多态 In X.method, the meaning of method depends on the type (class) of X. Encapsulation封装 Methods and operators implement behavior; data hiding is a convention by 阅读全文
posted @ 2011-10-13 11:31
方倍工作室
阅读(445)
评论(0)
推荐(0)
摘要:
第八章、 第一个python程序#!/usr/bin/env pythonimport osimport sysimport time source = [r'G:\s1', r'G:\s2']target_dir = r'G:\d' + os.sep today = target_dir + time.strftime('%Y%m%d')now = time.strftime('%H%M%S') comment = raw_input('Enter a commnet -->')if len 阅读全文
posted @ 2011-10-13 11:24
方倍工作室
阅读(318)
评论(0)
推荐(0)
摘要:
Python中有三种内建的数据结构——列表、元组和字典。 1) Lists列表 [,] 列表是序列的一种 shoplist = ['apple', 'carrot', 'banana']print shoplist #['apple', 'carrot', 'banana']shoplist.append('orange') #末尾加入一个print shoplist #['apple', 'carrot', 'banana', 阅读全文
posted @ 2011-10-13 11:23
方倍工作室
阅读(892)
评论(1)
推荐(2)
摘要:
第六章、 模块1) 模块sys模块字节编译的.pyc文件,优化编译后生成pyo文件2) from..import语句import sys print 'The command line arguments are:' for i in sys.argv: print i print '\n\nThe PYTHONPATH is', sys.path, '\n' 3) __name__只想在程序本身被使用的时候运行主块,而在它被别的模块输入的时候不运行主块from sys import * print 'The command line a 阅读全文
posted @ 2011-10-13 11:21
方倍工作室
阅读(413)
评论(0)
推荐(0)
摘要:
第五章、 函数 定义语句后面要加冒号 1) 定义函数 def sayHello(): print 'Hello World!'sayHello() 2) 变量作用域 LEGB原则 L本地作用域 E上层结构中def或lambda的作用域 G全局作用域 B内置作用域3) 工厂/闭合函数 def maker(N): def action(X): return X ** N return action f = maker(2)print f #<function action at 0x00E87730>print f(3) #9print f(4) #16g =... 阅读全文
posted @ 2011-10-13 11:19
方倍工作室
阅读(527)
评论(0)
推荐(0)
摘要:
第四章、 控制流 控制语句后面要加冒号: 1) if语句 if guess == number: print 'Congratulations, you guessed it.' # New block starts hereelif guess < number: print 'No, it is a little higher than that' # Another blockelse:print 'No, it is a little lower than that' if not False and True: #组合条件 pri 阅读全文
posted @ 2011-10-13 11:14
方倍工作室
阅读(347)
评论(0)
推荐(0)
摘要:
第三章、 运算符与表达式 1) 运算符 + 加 - 减 * 乘 ** 幂 / 除 // 取整除 % 取模 << 左移 >> 右移 & 按位与 | 按位或 ^ 按位异或 ~ 按位翻转 < 小于 > 大于 <= 小于等于 >= 大于等于 == 等于 != 不等于 not 布尔“非” and 布尔“与” or 布尔“或”运算符优先级 建议用括号来设置优先级2) 表达式 length = 5 breadth = 2 area = length * breadth 阅读全文
posted @ 2011-10-13 11:12
方倍工作室
阅读(337)
评论(0)
推荐(0)
摘要:
第二章、 类型常量5,1.23,9.25e-3,’This is a string’,”It’s a string!”1) 数整数:2长整数:浮点数:3.23,52.3E-4复数:-5+4j,2.3-4.6jac =-8.33 +1.2j print ac.real #-8.33 print ac.imag #1.2 print ac.conjugate() #(-8.33-1.2j) 二进制:0b1000八进制:0o307十六进制:0xFF2) 字符串单引号(')'Quote me on this'双引号(")"What's your na 阅读全文
posted @ 2011-10-13 10:29
方倍工作室
阅读(540)
评论(0)
推荐(0)
摘要:
第一章、 简介官方介绍:Python是一种简单易学,功能强大的编程语言,它有高效率的高层数据结构,简单而有效地实现面向对象编程。Python简洁的语法和对动态输入的支持,再加上解释性语言的本质,使得它在大多数平台上的许多领域都是一个理想的脚本语言,特别适用于快速的应用程序开发。安装:Python:http://www.python.org/download/PyScripter:http://code.google.com/p/pyscripter/UltraEdit的Python语法高亮:http://www.ultraedit.com/downloads/extras.htmlPython 阅读全文
posted @ 2011-10-13 10:22
方倍工作室
阅读(813)
评论(1)
推荐(1)