• python练习小册1


    6月18日

    首先是一个关于图片水印的,通过使用PIL模块进行的,

    from PIL import Image,ImageDraw,ImageFont
    
    def add_num(img):
        draw = ImageDraw.Draw(img)
        myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=40)
        fillcolor = "#ff0000"
        width, height = img.size
        draw.text((width-50, 5), '99', font=myfont, fill=fillcolor)
        img.save('result.jpg','jpeg')
        img.show
        return 0
    if __name__ == '__main__':
        image = Image.open('1.jpg')
        add_num(image)
        image.show()

    第二个便是随机生成200激活码

    首先利用random模块进行对字母数字的随机选取

    import random,string
    import uuid
    chars = string.ascii_letters +string.digits
    print(chars)
    s = "".join(random.choice(chars) for i in range(10))
    ge = "".join(random.sample(chars,10))  #随机十位
    print(s+"           "+ge)

    再通过嵌套函数的方式进行激活码的编写

    import random,string
    import uuid
    chars = string.ascii_letters +string.digits
    print(chars)
    s = "".join(random.choice(chars) for i in range(10))
    ge = "".join(random.sample(chars,10))  #随机十位
    print(s+"           "+ge)
    
    def generate(n,many):
        def getCode(n):
            return "".join(random.sample(chars, n))
        gene = [getCode(n) for i in range(many)]    #many个
        return  gene
    
    def wri(n,many,where):
        count = 1
        for i in generate(n,many):
            with open(where,"a") as boom:
                boom.write(str(count).rjust(3)+"   "+i+"
    ")
            count += 1
    
    if __name__ == '__main__':
        wri(20,200,"output.txt")
  • 相关阅读:
    缓存IO读写的方式
    mapboxgl 纠偏百度地图
    GIS常用算法
    DevExpress VCL TdxBar工具栏上的按钮等居右对齐无效的问题
    dxRichEditControl、Invalid operation in GDI+ (Code: 2)
    Indy+POP/SMTP收发邮件
    VUE父组件给子组件传对象
    Linux下进程间通信
    Linux下守护进程
    Linux下进程控制相关
  • 原文地址:https://www.cnblogs.com/NCLONG/p/13160954.html
Copyright © 2020-2023  润新知