1. 传入绝对文件名,得到目录名
dirpath = os.path.dirname(filepath)
常用的:根据当前执行py文件得到当前目录,然后加入系统路径
cur_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(cur_dir)
2. global 声明全局变量
如果全部变量会在某个函数中重新赋值,必须在该函数中用global 声明全局变量,否则,在其他地方在用该变量时,仍然是最开始的初始值
3. dict无append()方法,否则报错:AttributeError: 'dict' object has no attribute 'append'
对dict新增元素,用update()方法