摘要: Python Socket Socket 是一切网络通信的基础,socket 是一个网络通信两端的虚拟端点 (virtual endpoints), socket 可以被配置为一个 server that listen for incoming messages. 也可以是一个连接其他应用的客户端。 阅读全文
posted @ 2016-07-09 11:17 garyyang 阅读(178) 评论(0) 推荐(0)
摘要: 多态 我们编写一个名为 Animal 的 class, 有一个 run() 方法可以直接打印: 要理解多态的好处,我们还需要再编写一个函数,这个函数接受一个 Animal 类型的变量: 当我们传入Animal的实例时,run_twice()就打印出: 如果我们再定义一个Tortoise类型,从 An 阅读全文
posted @ 2016-07-01 18:36 garyyang 阅读(171) 评论(0) 推荐(0)
摘要: subprocess The subprocess module allows us to: To run UNIX commands we need to create a subprocess that runs the command. The recommended approach to 阅读全文
posted @ 2016-06-25 02:58 garyyang 阅读(148) 评论(0) 推荐(0)
摘要: 正则表达式 元字符 (metacharacters) [], 用来指定一个字符集(character class),字符集可以单个列出或者指定一个范围,For example, [abc] will match any of the characters a, b, or c; this is th 阅读全文
posted @ 2016-06-18 02:00 garyyang 阅读(145) 评论(0) 推荐(0)
摘要: 进一步理解装饰器 如果有如下逻辑: 如果我们把 query_user 的具体逻辑再封装为一个新函数,然后将新函数传入 query_data, 那么以后再需要不同的查询方法,就再封装新的函数就可以了。 那么,query_data 就是 query_user 的装饰。但是如果我们想保持 query_us 阅读全文
posted @ 2016-06-18 02:00 garyyang 阅读(147) 评论(0) 推荐(0)
摘要: 高阶函数 函数可以赋值给变量 即变量可以指向函数,如果一个变量指向了一个函数,那么可以通过该变量调用这个函数。函数名其实就是指向函数的变量。 既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数。 函数作为返回值 高阶函数除了可以接受函数作为 阅读全文
posted @ 2016-06-03 17:10 garyyang 阅读(149) 评论(0) 推荐(0)
摘要: 函数: 定义函数: def function (param1, param2...): body return XXX 函数名用小写 函数参数: 普通参数 默认参数,即调用函数 send_1 时可以不传入 b 参数,b 参数值默认为 'gary' # 默认参数 def send_1(a, b='ga 阅读全文
posted @ 2016-05-27 23:07 garyyang 阅读(152) 评论(0) 推荐(0)
摘要: Data Type List Compound data type, used to group together other values, which can be written as a list of comma-separated values (items) between squar 阅读全文
posted @ 2016-05-18 16:04 garyyang 阅读(150) 评论(0) 推荐(0)
摘要: Basic Rules Always use the extension .py. Always use #!/usr/bin/env python as shabang line. Variable Naming rule: Names must start with a letter or an 阅读全文
posted @ 2016-05-13 15:57 garyyang 阅读(180) 评论(0) 推荐(0)