• Python


    自己不从事开发工作,方便自己工作时写了个小工具。

    准备后面写成GUI图形化工具,先把代码保存在这里

    待完善...

    import os
    import string
    import time
    
    
    # 获取磁盘列表,返回list
    def get_disklist():
        disk_list = []
        for i in string.ascii_uppercase:
            disk = i + ':'
            if os.path.isdir(disk):
                disk_list.append(disk)
        return disk_list
    
    
    # 读取文件方法
    def read_file():
        # 最后一个(新增的)盘符路径赋给t
        t = get_disklist()[-1]
        # sn为需要读取的文本名称(存放SN码的文件)
        c = t + r'sn'
        with open(c, 'r') as files:
            str_num = files.read()
        return str_num
    
    
    # 加密方法
    def author(xin):
        #公司机密,不方便透露
        return str1
    
    
    if __name__ == '__main__':
        # 计数器
        a = 0
        while True:
            # 3为可变动数字,请改为未插入U盘前的磁盘分区数
            if len(get_disklist()) > 3:
                read_num = read_file()
                print('读取到的初始值为:{}'.format(read_num))
                # 2d27572e
                if read_num == '2d27572e':
                    print('sn为初始值,请使用树莓派启动此内存卡后再使用此脚本')
                else:
                    # 调用author方法得到需要的结果值
                    write_num = author(read_num)
                    # print(write_num)
                    w_way = get_disklist()[-1] + r'author'
                    # print(w_way)
                    # 写入文件
                    with open(w_way, 'w') as f:
                        f.write(write_num)
                        print('写入成功')
                    print('写入值为:{}'.format(write_num))
                    # 烧写成功后计数器+1
                    a += 1
                    print('刚刚烧录的是第{}张内存卡'.format(a))
                    while True:
                        if len(get_disklist()) > 3:
                            print('请拔出U盘')
                            time.sleep(2)
                        else:
                            break
            else:
                print('请插入新的U盘')
    
            time.sleep(2)
  • 相关阅读:
    webpack 性能优化
    Bert模型实现垃圾邮件分类
    基于SKLearn的SVM模型垃圾邮件分类——代码实现及优化
    sklearn中,数据集划分函数 StratifiedShuffleSplit.split() 使用踩坑
    mysql5.7安装教程【转载】
    Postman 使用小技巧/指南
    如何知道 window 的 load 事件已经触发
    前端常用库 CDN
    使用 rollup 打包可按需加载的 NPM 包
    webpack 4 快速搭建
  • 原文地址:https://www.cnblogs.com/cxstudypython/p/12191961.html
Copyright © 2020-2023  润新知