每次1. list

问题: 某地方参数需要传入一个list

当时采用的方法为:

phone_list = []
send_message(phone_list.append(get_phone_numbers(authorization_code)),....)
 
 # phone_list = []
 # phone_list.append(get_phone_numbers(authorization_code))
 # send_message(phone_list,........)

1-2 行的方式 获取的是append这个函数的返回值。但是这个函数返回值为None

5-6 行获取的才是list真正的值

2.list.append 数据覆盖问题

问题:每次输出字典的内容是不一样的,但是append入list的时候前面数据都会被覆盖

'''
遇到问题没人解答?小编创建了一个Python学习交流QQ群:778463939
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
def get_init_list():
    insert_list = []
    temp_path_dict = {}
    for dir_path, dir_names, file_names in os.walk(base_config['root_path']):
          省略部分
            if not white_flag:
                # temp_path_dict = {} 应该被插入的部分
                temp_path_dict['filePath'] = full_path
                temp_path_dict['fileMd5'] = get_file_md5(full_path)
                print(id(temp_path_dict))
                insert_list.append(temp_path_dict)

    return insert_list

Python 常见语法逻辑错误收集_python
可以看出,字典的部分是定义在循环外面的,虽然里面字典的值变了,但是赋值的都是相同的位置

如果在应该插入部分,每次dict的空间都是申请的新的空间,所以不会出现最后list 所有值都一样的问题