首页 > 编程语言 >Python 批量修改文件/文件夹名

Python 批量修改文件/文件夹名

时间:2024-12-12 09:58:07浏览次数:13  
标签:full name 批量 Python self list 文件夹 path part

Python 批量修改文件/文件夹名

1.简介:

使用python tkinter模块制作的一个界面化批量重命名文件以及文件夹的工具。资源已打包,大家可自行下载。

功能升级:

1.增加了多个文件选择的功能,并不需要一定选择文件夹。
2.增加了保留源文件名功能,可以在源文件名基础上加数字字母。
3.增加了标准数字功能即可以使用001,002,003,004来进行命名。
3.将多个按钮合并为一个确定按纽,修改了很多bug。

2.运行效果:

在这里插入图片描述

3.相关源码:

from tkinter import *
from tkinter import messagebox
from tkinter.filedialog import askdirectory
import os
import tkinter as tk
from tkinter import ttk
import re
from tkinter import filedialog


class GUI(Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.creat_window()
        self.path = "d:/"

    def creat_window(self):
        """窗口组件"""

        self.f1 = Frame(self)
        self.f1.pack()
        self.f3 = Frame(self)
        self.f3.pack(side="right")
        self.f2 = Frame(self)
        self.f2.pack()
        self.fintenger = Frame(self.f2)
        self.fintenger.grid(row=5, column=0, columnspan=2)
        self.finside = Frame(self.f2)
        self.finside.grid(row=2, column=0)
        self.f4 = Frame(self.f2)
        self.f4.grid(row=7, column=0)
        l1 = Label(self.f1, text="批量更改文件名", bg="pink", fg="white", fon=("宋体", 20))
        l1.grid(row=0, column=0, rowspan=2, columnspan=2, sticky=NSEW)
        self.l2 = ttk.Entry(self.f2)
        self.l2.insert(0, "文件夹路径")
        self.l2.grid(row=1, column=0, stick=EW, pady=20)
        butn2 = ttk.Button(self.f2, text="选择多个文件", command=self.choose_files)
        butn2.grid(row=2, column=1)
        self.b = StringVar()
        self.b.set("0")
        self.b1 = ttk.Radiobutton(self.finside, text="文件夹", value="0", variable=self.b)
        self.b2 = ttk.Radiobutton(self.finside, text="文件", value="1", variable=self.b)
        self.b1.grid(row=2, column=0)
        self.b2.grid(row=2, column=1)
        # butn3 = ttk.Button(self.finside, text="ensure", command=self.check_file_type)
        # butn3.grid(row=2,column=2)
        co = ttk.Button(self.f2, text="选择文件夹", command=self.coll)
        co.grid(row=1, column=1, sticky=EW)
        self.entry01 = ttk.Entry(self.f2)
        # self.entry01.insert(0, "更改后文件名")
        self.entry01.grid(row=3, column=0, sticky=NSEW, pady=20)
        self.btn = ttk.Button(self.f2, text="更改文件名", command=self.inform)
        self.btn.grid(row=3, column=1, sticky=EW)
        self.v = StringVar()
        self.v.set("0")
        self.v1 = ttk.Radiobutton(self.f2, text="前缀名", value="0", variable=self.v)
        self.v2 = ttk.Radiobutton(self.f2, text="后缀名", value="1", variable=self.v)
        self.v1.grid(row=4, column=0)
        self.v2.grid(row=4, column=1)
        # self.checkbutn()
        self.l3 = Text(self.f3, width=50, height=19, bg="lightblue", yscrollcommand=True)
        scroll = ttk.Scrollbar(self.f3, orient=VERTICAL, takefocus=0.1)
        scroll.place(relwidth=0.04, relheight=1, relx=0.9575, rely=0)
        scroll.config(command=self.l3.yview)
        self.l3.config(yscrollcommand=scroll.set)
        self.l3.pack(padx=25, pady=0)
        self.ra = StringVar()
        self.ra.set("0")
        self.ra3 = ttk.Radiobutton(self.fintenger, text="标准数字", value="2", variable=self.ra)
        self.ra1 = ttk.Radiobutton(self.fintenger, text="数字排前", value="0", variable=self.ra)
        self.ra2 = ttk.Radiobutton(self.fintenger, text="数字排后", value="1", variable=self.ra)
        self.ra3.pack(side="left")
        self.ra1.pack(side="left")
        self.ra2.pack(side="left")
        self.r = StringVar()
        self.r.set("1")
        self.r1 = ttk.Radiobutton(self.f2, text="使用正则", value="0", variable=self.r)
        self.r2 = ttk.Radiobutton(self.f2, text="不使用正则", value="1", variable=self.r)
        self.r1.grid(row=6, column=0)
        self.r2.grid(row=6, column=1)
        self.e = StringVar()
        self.e.set("1")
        self.e1 = ttk.Radiobutton(self.f4, text="保留文件名", value="0", variable=self.e)
        self.e2 = ttk.Radiobutton(self.f4, text="取消", value="1", variable=self.e)
        self.e1.pack(side="left")
        self.e2.pack(side="left")
        # butn4 = ttk.Button(self.f4, text="确定保留", command=self.reserve_old_filename)
        # butn4.pack(side="left")
        butn_help = ttk.Button(self.f2, text="help", command=self.help)
        butn_help.grid(row=7, column=1)
        butn = ttk.Button(self.f2, text="确定", command=self.justyfilename)
        butn.grid(row=8, column=1, sticky=EW)

    def reserve_old_filename(self):
        """保留源原文件名并加现在想要的格式"""
        reserve_information = self.e.get()
        if reserve_information == "0":
            part_name = self.entry01.get()
            self.l3.insert(INSERT, part_name)
            f_name = self.ra.get()
            """数字排前拍后"""
            """使用正则不使用正则"""
            try:
                list_dir = os.listdir(self.path)
                self.l3.insert(INSERT, "前缀名\n")
                i = 0
                for listna in list_dir:
                    list_name = self.path + listna
                    b_name = listna.split(".")[-1]
                    origion_name = listna.split(".")[0]
                    if f_name == "0":
                        """数字排前"""
                        i += 1
                        line_name = i
                        """计数"""
                        full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                        os.rename(list_name, full_name)
                        self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                    elif f_name == "1":
                        """数字排后"""
                        i += 1
                        line_name = i
                        full_name = self.path + str(origion_name) + str(line_name) + "." + b_name
                        os.rename(list_name, full_name)
                        self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                    elif f_name == "2":
                        # print("*" * 60)
                        i += 1
                        line_name = i
                        if i < 10:
                            full_name = self.path + "00" + str(line_name) + str(origion_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif 100 > i >= 10:
                            full_name = self.path + "0" + str(line_name) + str(origion_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif i >= 100:
                            full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))

            except Exception:
                self.message()


    def choose_files(self):
        """选中多个文件"""
        try:
            self.path_origion = filedialog.askopenfilenames(title="打开多个文件")
            base_name = self.path_origion[0]
            i = 0
            for each_path in self.path_origion:
                self.l3.insert(INSERT, each_path+"\n")
                # print(each_path)
                i += 1
                self.l2.insert(0, each_path)
            self.l3.insert(INSERT, "选中%s个文件" % i+"\n")
            filename = self.path_origion[0].split("/")[-1]
            self.path = base_name.replace(filename, "")
            self.l3.insert(INSERT, "文件路径为{}".format(self.path) + "\n")
            """****************************************************************
                主要功能self.check_file_type()以及self.justifyfilename()
                ****************************************************************
            """


        except Exception:
            self.choose_filetree()
            # print("发生错误了,an error ocured")
            # raise

    def help(self):
        """选用文件夹 确定按键"""
        information = """\n                       < 帮助 >\n\n------------------------------------------------\n1.    选择文件夹或者选择多个文件后,记得把单选框打勾。\n\n2.    标准数字 单选框是有些软件只能识别001,002,010,020这样的文件名,该选项就是这个意思。\n\n3.    保留文件名的意思是在源文件名基础之上加数字或者字母。\n\n4.   可能tkinter有bug,输入框或者text文本框删除文本后会有一个小方框\n\n------------------------------------------------"""
        messagebox.showinfo(message=information)
        self.l3.insert(INSERT, information)

    def justyfilename(self):
        """选择文件夹调用函数"""
        reserve_information = self.e.get()
        value = self.b.get()
        if value == "0":
            """选择文件夹"""
            part_name = self.entry01.get()
            self.l3.insert(INSERT, part_name)
            f_name = self.ra.get()
            """数字排前拍后"""
            re_name = self.r.get()
            """使用正则不使用正则"""
            lis = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
                   "u",
                   "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
                   "P",
                   "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
            reserve_information = self.e.get()
            if reserve_information == "0":
                part_name = self.entry01.get()
                self.l3.insert(INSERT, part_name)
                f_name = self.ra.get()
                """数字排前拍后"""
                """使用正则不使用正则"""
                try:
                    list_dir = os.listdir(self.path)
                    self.l3.insert(INSERT, "前缀名\n")
                    i = 0
                    for listna in list_dir:
                        list_name = self.path + listna
                        b_name = listna.split(".")[-1]
                        origion_name = listna.split(".")[0]
                        if f_name == "0":
                            """数字排前"""
                            i += 1
                            line_name = i
                            """计数"""
                            full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif f_name == "1":
                            """数字排后"""
                            i += 1
                            line_name = i
                            full_name = self.path + str(origion_name) + str(line_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif f_name == "2":
                            i += 1
                            line_name = i
                            if i < 10:
                                full_name = self.path + "00" + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif 100 > i >= 10:
                                full_name = self.path + "0" + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif i >= 100:
                                full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))

                except Exception:
                    self.reserve_old_filenametree()
            else:
                try:
                    list_dir = os.listdir(self.path)
                    if self.v.get() == "1":
                        """判断后缀名"""
                        for listna in list_dir:
                            list_name = self.path + listna
                            b_name = listna.split(".")[0]
                            full_name = self.path + b_name + "." + str(part_name)
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                    else:
                        self.l3.insert(INSERT, "前缀名\n")
                        """判断前缀名"""
                        i = 0
                        for listna in list_dir:
                            list_name = self.path + listna
                            b_name = listna.split(".")[1]
                            # print(b_name)
                            if re_name == "0":
                                """使用正则"""
                                re_part_name = re.findall('.*\[(.*)\].*', part_name)[0]
                                part_name1 = part_name.split("[")[0]
                                part_name3 = part_name.split("]")[-1]
                                part_name2 = part_name.split("[")[1].replace("1-9]", "")
                                if "1-9" in re_part_name:
                                    """[1-9]判断"""
                                    # print("jjjjjjjjh")
                                    i += 1
                                    full_name = self.path + part_name1 + str(i) + part_name2 + part_name3 + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                elif "a-z" in re_part_name:
                                    """"[a-z]判断"""
                                    en_name = lis[i]
                                    i += 1
                                    part_name2 = part_name.split("[")[1].replace("a-z]", "")
                                    full_name = self.path + part_name1 + str(en_name) + part_name3 + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif re_name == "1":  # 不使用正则
                                """不使用正则"""
                                if f_name == "0":
                                    i += 1
                                    line_name = i
                                    full_name = self.path + str(line_name) + str(part_name) + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                else:
                                    i += 1
                                    line_name = i
                                    full_name = self.path + str(part_name) + str(line_name) + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                except Exception:
                    self.no_reserve_old_filenames()
        else:
            """选择单个文件
                保留原文件名"""
            if reserve_information == "0":
                part_name = self.entry01.get()
                self.l3.insert(INSERT, part_name)
                f_name = self.ra.get()
                """数字排前拍后"""
                """使用正则不使用正则"""
                list_dir = self.path_origion
                self.l3.insert(INSERT, "前缀名\n")
                i = 0
                for listna in list_dir:
                    listna = listna.replace(self.path, "")
                    list_name = self.path + listna
                    b_name = listna.split(".")[-1]
                    origion_name = listna.split(".")[0]
                    try:
                        if f_name == "0":
                            """数字排前"""
                            i += 1
                            line_name = i
                            """计数"""
                            full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif f_name == "1":
                            """数字排后"""
                            i += 1
                            line_name = i
                            full_name = self.path + str(origion_name) + str(line_name) + "." + b_name
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                        elif f_name == "2":
                            i += 1
                            line_name = i
                            if i < 10:
                                full_name = self.path + "00" + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif 100 > i >= 10:
                                full_name = self.path + "0" + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif i >= 100:
                                full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                                os.rename(list_name, full_name)
                                self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                    except Exception:
                        self.reserve_filenames()
                        # raise
            else:
                part_name = self.entry01.get()
                self.l3.insert(INSERT, part_name)
                f_name = self.ra.get()
                """数字排前拍后"""
                re_name = self.r.get()
                """使用正则不使用正则"""
                lis = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
                       "s", "t",
                       "u",
                       "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                       "N", "O",
                       "P",
                       "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
                list_dir = self.path_origion
                try:
                    if self.v.get() == "1":
                        """判断后缀名"""
                        for listna in list_dir:
                            listna = listna.replace(self.path, "")
                            b_name = listna.split(".")[-1]
                            list_name = self.path + listna
                            full_name = self.path + b_name + "." + str(part_name)
                            os.rename(list_name, full_name)
                            self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                    else:
                        self.l3.insert(INSERT, "前缀名\n")
                        """判断前缀名"""
                        i = 0
                        for listna in list_dir:
                            listna = listna.replace(self.path, "")
                            list_name = self.path + listna
                            b_name = listna.split(".")[-1]
                            if re_name == "0":
                                """使用正则"""
                                re_part_name = re.findall('.*\[(.*)\].*', part_name)[0]
                                part_name1 = part_name.split("[")[0]
                                part_name3 = part_name.split("]")[-1]
                                part_name2 = part_name.split("[")[1].replace("1-9]", "")
                                if "1-9" in re_part_name:
                                    """[1-9]判断"""
                                    i += 1
                                    full_name = self.path + part_name1 + str(
                                        i) + part_name2 + part_name3 + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                elif "a-z" in re_part_name:
                                    """"[a-z]判断"""
                                    en_name = lis[i]
                                    i += 1
                                    part_name2 = part_name.split("[")[1].replace("a-z]", "")
                                    full_name = self.path + part_name1 + str(en_name) + part_name3 + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                            elif re_name == "1":  # 不使用正则
                                """不使用正则"""
                                if f_name == "0":
                                    i += 1
                                    line_name = i
                                    full_name = self.path + str(line_name) + str(part_name) + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                elif f_name == "1":
                                    i += 1
                                    line_name = i
                                    full_name = self.path + str(part_name) + str(line_name) + "." + b_name
                                    os.rename(list_name, full_name)
                                    self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                elif f_name == "2":
                                    # print("*" * 60)
                                    i += 1
                                    line_name = i
                                    if i < 10:
                                        full_name = self.path + "00" + str(line_name) + str(origion_name) + "." + b_name
                                        os.rename(list_name, full_name)
                                        self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                    elif 100 > i >= 10:
                                        full_name = self.path + "0" + str(line_name) + str(origion_name) + "." + b_name
                                        os.rename(list_name, full_name)
                                        self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))
                                    elif i >= 100:
                                        full_name = self.path + str(line_name) + str(origion_name) + "." + b_name
                                        os.rename(list_name, full_name)
                                        self.l3.insert(INSERT, "文件%s重命名成功,新的文件名为%s\n" % (list_name, full_name))

                except Exception:
                    self.mess_manyfiles()
                    # raise

    def mess_manyfiles(self):
        messagebox.showinfo(title="<justyfilename函数报错>", message="justyfilename 选择多个文件函数报错,370行之后代码,")

    def choose_filetree(self):
        messagebox.showinfo(title="<choose_files函数报错>", message="choose_files 选择多个文件函数报错,165行之后代码,")

    def reserve_filenames(self):
        messagebox.showinfo(title="<justyfilename函数报错>", message="justyfilename 选择多个文件保留源文件名函数报错,320行之后代码,")

    def no_reserve_old_filenames(self):
        messagebox.showinfo(title="<justyfilename函数报错>", message="justyfilename 选择文件夹不保留源文件名函数报错,264行之后代码,")

    def reserve_old_filenametree(self):
        messagebox.showinfo(title="<justyfilename函数报错>", message="justyfilename 选择文件夹不保留源文件名函数报错,222行之后代码,")

    def reserve_old_filename_error(self):
        messagebox.showinfo(title="<reserve_old_filename函数报错>", message="jreserve_old_filename 保留源文件名函数报错,112行之后代码,")

    def inform(self):
        messagebox.showinfo(title="<注意>", message="直接输入文件名,无需加点")

    def message(self):
        messagebox.showinfo(title="<注意>", message="请输入文件夹路径,并按顺序完成,或出现了某种未知错误")

    def coll(self):
        """选择文件夹路径"""
        self.path = askdirectory(title="选择文件", initialdir="d:/")
        self.path = self.path+"/"
        # print(self.path)        #要增加判断文件夹还是多个文件
        # 判断前缀,加字母数字下划区分
        self.l3.insert(INSERT, self.path)
        self.l2.insert(0, self.path)


if __name__ == '__main__':
    """程序主窗体"""
    root = Tk()
    root.geometry("730x340+200+200")
    root.title("批量更改文件名工具")
    # root.iconbitmap("b.ico")
    root.resizable(width=False, height=False)
    app = GUI(master=root)
    root.wm_attributes("-alpha", 0.86)  # 透明度(0.0~1.0)
    root.wm_attributes("-toolwindow", True)  # 置为工具窗口(没有最大最小按钮)
    root.wm_attributes("-topmost", True)  # 永远处于顶层
    # root.overrideredirect(True)
    root.mainloop()

标签:full,name,批量,Python,self,list,文件夹,path,part
From: https://blog.csdn.net/Clay_K/article/details/144407338

相关文章

  • Python3 条件控制
    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块。可以通过下图来简单了解条件语句的执行过程:代码执行过程:if语句Python中if语句的一般形式如下所示:ifcondition_1:statement_block_1elifcondition_2:statement_block_2else......
  • 基于遗传算法的梯级水电站群优化调度研究(Python代码实现)
     ......
  • Python学习笔记 - 探索列表与字典的特殊操作
    Python编程的核心数据结构之一是列表和字典。列表是一种可以存储有序数据的容器,而字典是一种通过键值对存储数据的结构。灵活运用列表与字典可以使代码更具可读性和高效性,尤其是在处理大量数据时。本教程将系统地介绍列表和字典的一些特殊操作,包括基本用法、应用实例,并讲解......
  • Python随机抽取Excel数据并在处理后整合为一个文件
      本文介绍基于Python语言,针对一个文件夹下大量的Excel表格文件,基于其中每一个文件,随机从其中选取一部分数据,并将全部文件中随机获取的数据合并为一个新的Excel表格文件的方法。  首先,我们来明确一下本文的具体需求。现有一个文件夹,其中有大量的Excel表格文件(在本文中我们就......
  • Python OpenCV按照像素点图片切割
    图像分割是从图像处理到图像分析的关键步骤,在目标检测、特征提取、图像识别等领域具有广泛应用。OpenCV是一个强大的计算机视觉库,提供了多种图像分割方法。本文将详细介绍如何使用Python和OpenCV进行基于像素点的图像分割,包括阈值分割、自适应阈值分割、Otsu's二值化、分水岭算法......
  • 《Python 爬取上海软科中国大学排名并存入表格:详解与速通指南》
     大家好啊!我是NiJiMingCheng我的博客:NiJiMingCheng上一节我们分享了安装selenium的内容,这一节我们继续来实战,这一节我们主要学习爬取上海软科中国大学排名并存入表格,本文仅以办学层次进行演示,其他数据同理可得,加油Selenium各浏览器驱动下载与配置使用(详细流程)目录结......
  • 【2024年华为秋招-12月11日-第二题(200分)- 服务器训练任务调度】(题目+思路+Java&C++&Py
    题目内容团队申请了一组服务器,用于机器学习训练,为了充分利用资源,需要你来完成任务调度算法的实现。一台服务器同一时间只能执行一个训练任务,每个训练任务有训练时间和优先级。当空闲服务器不足时,优先执行高优先级的训练任务;如果多个训练任务的优先级相同,优先执行训练时......
  • python中的反射
    cProfile.run('re.compile("foo|bar")','restats')https://docs.python.org/3/library/profile.htmlimportcProfileimportrecProfile.run('re.compile("foo|bar")') 这段python的闪耀点是环境感知能力 exec查看实现,其调用的是pyt......
  • Python单元测试:构建稳健代码的关键
    引言在软件开发中,测试是确保代码质量和可靠性的必要环节。单元测试是验证单个组件或模块是否按预期工作的测试方法。它通过自动化测试来检验每个功能模块的正确性,帮助团队及早发现和修复潜在的问题。本文将深入探讨Python中的单元测试,包括如何编写和运行测试、常用的测试框架......
  • Linux如何挂载windows共享文件夹(包含Linux报错解决)
     目录前言windows如何共享文件夹windows如何查看共享Linux端挂载共享文件夹关于挂载共享文件夹的报错解决1.关闭windows防火墙2.确认windows的CIFS文件共享功能是否开启3.检查源路径与挂载路径是否正确4.检查用户名及密码是否正确5.检查共享文件夹权限6.......