zoukankan      html  css  js  c++  java
  • 达观数据

    需求函数f 0.8的几率成功,0.2的几率失败,当它失败重试count次,重试count次后还是失败则打报错信息,装饰器实现

    # 有参装饰器
    def retry(count):
        def outter(func):
            def inner(*args, **kwargs):
                if isinstance(count, int):
                    for i in range(0, count):
                        try:
                            return func(*args, **kwargs)
                        except Exception as e:
                            if i == count - 1:
                                print(e)
                else:
                    raise Exception('传入类型错误')
            return inner
        return outter
    
    
    @retry(3)
    def f():
        print(1111)
        qq
    
    f()
    

    字符串 'abc_button(hello_world)'.lstrip('abc_').rstrip('(hello_world)') 的结果

    
    
    aa = 'abc_button(hello_world)'.lstrip('abc_').rstrip('(hello_world)')
    
    print(aa)  # utton
    

    'abc_hello(hello_world)' 怎么拿到中间的hello?

    ss = 'abc_button(hello_world)'
    import re
    l1=re.findall(r'_(.*?)(',ss)[0]
    print(l1)   #button
    
    

    将字典{'1':a, '2':b}中key的类型从str修改为int,即{1:a, 2:b}

    dic1 = {'1': 'a', '2': 'b'}
    new_dic = {}
    for k, v in dic1.items():
        k = int(k)
        # new_dic[k] = v
        # 或者
        new_dic.update({k: v})
    dic1 = new_dic
    print(dic1)
    
    作者:linqiaobao
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    吊打XXX
    [CQOI2011]动态逆序对
    陌上花开
    【BOI2007】摩基亚Mokia
    [SCOI2008]奖励关
    最小生成树
    打表
    【中学高级本】倒酒
    整数合并
    韩信点兵
  • 原文地址:https://www.cnblogs.com/linqiaobao/p/13579700.html
Copyright © 2011-2022 走看看