• __init__.py的作用
    • import的时候会调用该文件;
    • 文件中的__all__(列表)用于导入全部模块;
    • __init__.py文件将文件夹变为python模块/包;
  • python list extend()方法:
    • 用于在列表末尾追加另一个列表(append是追加一个值);
  • __import__() :动态加载类和函数
    • 参数只能是字符串,与import作用差不多;
    • 举例:import sys == __import__(’sys’)
  • python 中super的解析:
  • python 中字符串转int:
    • int函数会将输入base进制的字符串转换为十进制
    • 如:int(‘0x1010’, base=16)可以将16进制字符串转为10进制
  • python dict.get()与dict[‘key’]的区别:
    • dict['key']只能获取存在的值,如果不存在则触发KeyError而dict.get(key, default=None)则如果不存在则返回一个默认值,如果设置了则是设置的,否则就是None
  • 创建python运行的虚拟环境:
  • python多进程间的通信(Manager):
  • python的ConfigParser类用来解析conf文件时,conf文件的配置key必须为小写,如果为大写字母,该类会自动转为小写字符的key;
    • python 踩过的坑,一个个来填
  • python发送get/post请求的方法说明:
  • 字符编码检测:chardet局限性
    • chardet.detect(字符串),其中字符串不能为unicode编码的字符串;
  • re模块正则匹配的坑:
    • re.match(pattern,string),其中的pattern与string必须字符编码一致,否则无法正确匹配;
  • 嵌套for... [if] ...语句解析:
    • [s2 for s1 in a.split() for s2 in s1.split()] 
    • 等价于:
      • for s1 in a.split():
        • for s2 in s1.split():
          • print s2
  • str才能decode(“***”),unicode才能encode(“***”)
    • 判断str或者unicode的方法:isinstance(***, unicode/str)
  • dict转字符串,同时保持中文原样输出的办法:
    • json.dumps(rec_dict, ensure_ascii = False)
  • 通常如果出现诡异的编码问题,在文件开头使用以下代码会有意想不到的效果:


相关文章: