python 技巧

#conf文件中的字典是字符串格式,可通过eval()转换成字典
with open("./web_server.conf") as f:
    conf_info=eval(f.read())

 闭包内修改变量值

x=300
def test1():
    x=200
    def test2():
        nonloacl x #类似于global
        print('---1---%d'%x)
        x=100
        print('---2---x=%d'%x)
    return text2 # 返回test2的引用给test1的调用者
t1=test1() # 此时调用返回的是test2的引用
t1() #调用test2的函数
原文地址:https://www.cnblogs.com/zhangdingqu/p/9826947.html