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的函数

 

posted @ 2018-10-21 21:18  zhangdingqu  阅读(126)  评论(0编辑  收藏  举报