摘要:        
10 进程和多线程 10.1 多进程 # -*- coding: utf-8 -*- import os pid=os.fork() print ('process (%s)start ...' %os.getpid()) if pid==0: print('I am child process (    阅读全文
posted @ 2017-11-28 18:09
smartwen
阅读(144)
评论(0)
推荐(0)
        
            
        
        
摘要:        
9 IO编程 在Python中,文件读写是通过open()函数打开的文件对象完成的。使用with语句操作文件IO是个好习惯。 读文件 try: f = open('/path/to/file', 'r') print(f.read()) finally: if f: f.close() python    阅读全文
posted @ 2017-11-28 18:08
smartwen
阅读(773)
评论(0)
推荐(0)
        
            
        
        
摘要:        
8 错误,调试和测试 8.1错误处理 所有的异常来自 BaseException 记录错误 : # err_logging.py import logging def foo(s): return 10 / int(s) def bar(s): return foo(s) * 2 def main(    阅读全文
posted @ 2017-11-28 18:06
smartwen
阅读(159)
评论(0)
推荐(0)
        
            
        
        
摘要:        
7.面向对象高级编程 7.1使用__slots__ python动态语言,new 对象后绑定属性和方法 Tip:给一个实例绑定的方法,对其他对象无效。可以通过对class绑定后,所有对象可以调用该方法 如果我们现在只有实例可以添加属性,使用__slots__,只允许对Student实例添加name和    阅读全文
posted @ 2017-11-28 18:05
smartwen
阅读(216)
评论(0)
推荐(0)
        
            
        
        
摘要:        
6.面向对象 6.1类和实例 class Student(object): #注意:特殊方法“init”前后有两个下划线!!! def __init__(self,name,score):#第一个参数self永远是类创建的实例本身 self.__name=name self.__score=scor    阅读全文
posted @ 2017-11-28 18:04
smartwen
阅读(148)
评论(0)
推荐(0)
        
            
        
        
摘要:        
4.函数式编程 4.11高级函数 map接收2个参数,1个是函数对象本身,一个是Iterable list(map(str, [1, 2, 3, 4, 5, 6, 7, 8, 9])) ##reduce把结果继续和序列的下一个元素做累积计算 def f(x): ... return x * x re    阅读全文
posted @ 2017-11-28 18:02
smartwen
阅读(221)
评论(0)
推荐(0)
        
            
        
        
摘要:        
5.模块 5.1 使用模块 作用域 _private_1(name) 非公开的函数 私有的变量,外部不需要引用的函数全部定义成private #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' a test module ' #任何模块代码的第一个字符串    阅读全文
posted @ 2017-11-28 18:02
smartwen
阅读(116)
评论(0)
推荐(0)
        
            
        
        
摘要:        
3.高级特性 3.1切片 L = list(range(100)) L[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3 如果第一个索引是0,还可以省略 L[:3] 也支持取倒数元素 L[-2:] 取L集合的倒数2位元素 L[10:20] 取前11-20个数: L[:10:2]取前10个    阅读全文
posted @ 2017-11-28 18:00
smartwen
阅读(477)
评论(0)
推荐(0)
        
            
        
        
摘要:        
2.2定义函数: 函数体内部使用return 返回函数结果; 函数没有返回时,自动使用return None; 函数可以同时返回多个值,但其实就是一个tuple。 2.3 函数的参数,有位置参数 有默认参数 一是必选参数在前,默认参数在后,否则Python的解释器会报错 二是如何设置默认参数 默认参    阅读全文
posted @ 2017-11-28 17:59
smartwen
阅读(145)
评论(0)
推荐(0)
        
            
        
        
摘要:        
1、官网下载地址是:https://www.python.org/downloads/ 默认下载安装时记得勾选配置PATH路径 PIP工具包(我是选择Python 3.5的) 2、Windows 下打开cmd 用pip工具安装开发Web App需要的第三方库: pip3 install aiohtt    阅读全文
posted @ 2017-11-28 14:20
smartwen
阅读(307)
评论(0)
推荐(0)
        
 
                    
                     
                    
                 
                    
                 
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号