很久没有更新文章了,今天更新一个自己写的小工具 因工作需要,需要将一些图片和表格导出后分开存放在相应的目录,之前一直是手工创建并进行压缩太累,后面就想办法用python中的tkinter实现一个带界面的小工具...,来解放自己生成目录的重复性工作。..., height): """初始化窗口并居中显示""" self.master = master screenwidth = master.winfo_screenwidth...'.format(self.date1[5:], i)) for dir in self.dir_lists: if not os.path.exists...= self.roo_excel_path_Entry.get() if not len(self.roo_excel_path) == 0: if not os.path.exists
标准库中一个用于访问操作系统功能的模块,实现跨平台访问 import os print (os.sep) #系统路径的分隔符,windows是 “\\” print (os.name) #你正在使用的工作平台...(path) #判断文件或目录是否存在,Ture存在 os.path.isfile(path) #判断是否是文件 os.path.isdir(path) 判断是否为目录 path模块: os.path.basename...#拼接了路径 fullpath=os.path.join(dirs,files[0]) print fullpath #判断一个路径是否是一个文件,是否目录 if os.path.isfile...import os #coding=utf-8 '''编写程序: 1:能在当前目录下查找文件名包含指定字符串的文件 2:并打印出绝对路径 ''' sub_str="homework" cur_dir=os.getcwd...() #返回当前工作目录 files=os.listdir(cur_dir) for item in files: print item if os.path.isfile(os.path.join
Python实现 导入需要的库并设置目标文件夹路径 import os import glob import filecmp dir_path = r'C:\\xxxx' 接着遍历获取所有文件的绝对路径...由于遍历获取每一个文件或者文件夹后,需要判断是否是文件,如果是文件则可能将绝对路径存放到列表中,这里需要再完成两个事情: 首先创建一个空列表,后面用list.append(i)添加文件路径 接着利用os.path.isfile...= y and os.path.exists(x) and os.path.exists(y): if filecmp.cmp(x, y): os.remove...= y and os.path.exists(x) and os.path.exists(y): if filecmp.cmp(x, y): os.remove...最后还是希望大家能够理解Python办公自动化的一个核心就是批量操作-解放双手,让复杂的工作自动化! 今天的文章就到这里,原创不易,如果喜欢的话请给我一波三连支持吧(在看、转发、留言) ?
el 使用 os 模块 判断文件是否存在 os.path.isfile(path) 判断目录是否存在 os.path.isdir(path) 判断路径是否存在 # 使用 path 模块 os.path.exists...>>> os.path.exists(‘d:/assist/getTeacherList.py’) True >>> os.path.isfile(‘d:/assist’) False >>> os.path.isfile...getHash(f2) return str1==str2 if __name__ == ‘ 这篇文章主要介绍了基于python判断目录或者文件代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值...判断文件是否存在 import os os.path.exists(test_file.txt) #True os.path.exists(no_exist_file.txt) #Fa 该代码主要是基于...若存在删除文件夹下所有文件 if tf.gfile.Exists(folder): #返回一个list for file in (tf.gfile.ListDirectory(folder)): #添加绝对路径,并删除文
os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 print(os.getcwd()) E:\pycharm\test os.chdir(“dirname”) 改变当前脚本工作目录...os.removedirs(‘dirname1′) 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推 os.chdir('....os.rmdir(‘dirname’) 删除单级空目录,若目录不为空则无法删除。 os.rmdir('./path1') ?...print(os.path.exists('....否则返回False print(os.path.isfile('./log')) print(os.path.isfile('.
以下列举常用的命令 1. os.name——判断现在正在实用的平台,Windows 返回 ‘nt'; Linux 返回’posix' 2. os.getcwd()——得到当前工作的目录。...os.remove()——删除指定文件 5. os.rmdir()——删除指定目录 6. os.mkdir()——创建目录 注意:这样只能建立一层,要想递归建立可用:os.makedirs() 7. os.path.isfile...11. os.getcwd()——获得当前工作的目录(get current work dir) 12. os.system()——执行shell命令。...os.path.basename(path)——返回文件名 18. os.path.dirname(path)——返回文件路径 ◆实践吧◆ ◆两个小实例◆ #自定义函数:如果目录存在,输出”目录存在“,如果目录不存在,创建并输出...(path): if os.path.isfile(path): print("是文件,大小为",os.path.getsize(path)) elif
当前工作目录 每个运行在计算机上的程序,都有一个“当前工作目录”,或cwd。没有从根文件夹开始的文件名或路径,都假定在当前工作目录下。...os.path.isfile(path) 判断 path 参数是否是一个文件,如果是则返回 True,否则返回 False。...>>>path = os.getcwd() >>>os.path.exists(path) True >>>os.path.exists('D:\\read') False >>>os.path.exists...('D:\\Python study') True >>>os.path.isfile(path) False >>>os.path.isdir(path) True >>>os.path.isfile...步骤: import shelve 调用函数 shelve.open() 并传入一个文件名,然后将返回值(shelf值)保存在一个变量中。
os.getcwd()os.getcwd() 函数返回当前工作目录。...但是,如果目录不为空,则无法删除。import osos.rmdir('/Users/user/Desktop/new_dir')执行上述代码后,new_dir 目录将被删除。...os.path.exists(path):判断指定路径是否存在。os.path.isdir(path):判断指定路径是否是目录。os.path.isfile(path):判断指定路径是否是文件。...os.path.abspath(path))print('目录名称:', os.path.dirname(path))print('文件名称:', os.path.basename(path))if os.path.exists...(path): print('指定路径存在') if os.path.isdir(path): print('指定路径是目录') elif os.path.isfile(
(1)getcwd( ) 获取当前的工作路径 print(os.getcwd()) (2)chdir( ) 修改当前工作路径 path = os.path.sep+"Users"+os.path.sep...+"xiaoyu"+os.path.sep+"Desktop"+os.path.sep+"Demo"+os.path.sep os.chdir(path) # 调整当前的工作路径 file = "abc.txt...使用Base64编码存储图片、读取图片、展示图片; 案例: 将文件夹中的图片转为base64编码的二进制文件,并写入磁盘 import base64 path = "/Users/xiaoyu/Desktop...image.txt","wb") write_image.write(base64_data) write_image.close() 案例: 将base64编码的二进制文件解码成图片并写入磁盘...else: print("添加手机号码的编号成功") 好啦,关于Python的文件读写操作就介绍到这里,下一节我们继续介绍Python如何开发图形化界面:Tkinter模块的用法
in range(4)] for i in aaa print i 动态获取对象obj的文档字串 obj.doc OS的方法 os.mknod(“test.txt”) #创建空文件 windos环境下无法使用...os.getcwd()——得到当前工作的目录。...—删除指定文件 os.rmdir()——删除指定目录 删除多个目录:os.removedirs os.mkdir()——创建目录 注意:这样只能建立一层,要想递归建立可用:os.makedirs() os.path.isfile...os.path.exists()——检验指定的对象是否存在 os.system()——执行shell命令。...os.listdir()——指定所有目录下所有的文件和目录名 os.name()——判断现在正在用的平台,Windows 返回 ‘nt’; Linux 返回’posix’ 检验给出的路径是否是一个文件:os.path.isfile
掌握os模块中的文件和目录方法,可以极大地提高你在数据处理、系统管理、脚本编写等场景下的工作效率。本文将深入探讨os模块中与文件和目录操作相关的关键方法,并通过具体案例展示其实际应用。...current_dir = os.getcwd() print(current_dir) 2.2 os.chdir() chdir()方法用于更改当前工作目录。...os.removedirs('path/to/empty/directory') 三、文件操作方法 3.1 os.path.exists() exists()方法检查指定路径是否存在。...if os.path.exists('example.txt'): print("File exists") else: print("File does not exist") 3.2...os.path.isfile() isfile()方法判断指定路径是否为文件。
其中三巨头是Tkinter、wxPython和PyQt。这些工具包中的每一个都将与Windows、macOS和Linux一起工作,而PyQt具有在移动设备上工作的附加功能。...wxPython入门: GUI的定义 创建框架应用程序 创建工作应用程序 冲鸭!!!...wxPython与其他工具包(如PyQt或Tkinter)的主要区别在于,wxPython尽可能在本机平台上使用实际的小部件。这使得wxPython应用程序看起来与它所运行的操作系统是原生一体的。...当你阻止一个事件循环时,GUI将变得无响应并对用户显示为冻结状态。 在GUI中启动的任何进程,如果耗时超过四分之一秒,都应该作为单独的线程或进程启动。这将防止GUI冻结,并为用户提供更好的用户体验。...wxPython框架有特殊的线程安全方法,你可以使用这些方法与应用程序通信,让它知道线程已经完成,或进行更新。 让我们创建一个框架应用程序来演示事件是如何工作的。
os模块:提供对操作系统进行调用的接口 getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 import os print(os.getcwd()) 执行输出 E:\python_script...removedirs() 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推 os.removedirs(r"E:\python_script\a\b\c\d") 执行程序,查看目录,...rmdir() 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname os.rmdir(r"D:\a") 执行程序,查看目录是否删除了 listdir() 列出指定目录下的所有文件和子目录...返回True print(os.path.isabs(r"d:\b")) 执行输出 True os.path.isfile(path) 如果path是一个存在的文件,返回True。...否则返回False print(os.path.isfile(r"d:\b")) 执行输出 False os.path.isdir(path) 如果path是一个存在的目录,则返回True。
os.chdir(路径):切换路径 os.path.exists(文件名):判断当前路径是否存在 os.path.isfile(文件):判断当前路径是不是文件 os.path.isdir(文件夹):判断当前路径是否为文件夹...import os # 获取当前工作路径 print(os.getcwd()) # E:\Old_BoyClass_fourth 11、chdir(路径) 切换路径 import os #...获取当前工作路径 print(os.getcwd()) # E:\Old_BoyClass_fourth os.chdir('D:') print(os.getcwd()) # D:\ 12、os.path.exists...(os.path.exists(r'E:\Old_BoyClass_fourth\findtxt\z.txt')) # >>>False 13、os.path.isfile(文件) 判断是否为文件...sys.argv[ ] sys.argv[ ]其实就是一个列表,里边的项为用户输入的参数,关键就是要明白这参数是从程序外部输入的,而非代码本身的什么地方,要想看到它的效果就应该将程序保存了,从外部来运行程序并给出参数
#切换到上级目录 >>> os.chdir(os.pardir) >>> os.getcwd() 'E:\\' os.getcwd() 获取当前工作目录 >>> os.getcwd() 'E:\\'...>>> os.chdir("个人") >>> os.getcwd() 'E:\\个人' os.chdir(path) 切换到指定工作目录 >>> os.chdir("e:\\python") >>>...,如若也为空,则删除,如果目录不为空则不删除 >>> os.removedirs("e:\\e\\e") os.rmdir(path) 删除单级非空目录,若目录不为空则无法删除,会报错 >>> os.mkdir...(path) 判断path指定的目录或文件是否存在 >>> os.path.exists("e:\\python") True >>> os.path.exists("e:\\python\\3.txt...(path) 判断path是否是文件 >>> os.path.isfile("e:\\python\\3.txt") True >>> os.path.isfile("e:\\python") False
= filename self.directory = "file_split" self.split = int(split_number) if os.path.exists...key 和 iv 初始化 AES 对象,使用 MODE_CFB 模式 mycipher = AES.new(key, AES.MODE_CFB, iv) # 将iv(密钥向量)添加到加密密文的开头并一起传输...}".format(int(binary, 2))) except ValueError: print ("please choose a valid option") 19.CLI 待办事项应用程序...function1() 21.制作一个简单的秒表 import tkinter as Tkinter from datetime import datetime counter = 0 running..., fg='black', font='Verdana 30 bold') label.pack() f = Tkinter.Frame(root) start = Tkinter.Button(f,
os.getcwd()函数得到当前工作目录,即当前Python脚本工作的目录路径。...==================== os.path常用方法: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir(“dirname”) 改变当前脚本工作目录...获取当前目录的父目录字符串名:(‘..’) os.makedirs(‘dirname1/dirname2’) 可生成多层递归目录 os.removedirs(‘dirname1’) 若目录为空,则删除,并递归到上一级目录...如若也为空,则删除,依此类推 os.mkdir(‘dirname’) 生成单级目录;相当于shell中mkdir dirname os.rmdir(‘dirname’) 删除单级空目录,若目录不为空则无法删除...如果path是绝对路径,返回True os.path.isfile(path) 如果path是一个存在的文件,返回True。
# 举例,使用os模块创建一个文件夹的示例代码: import os dir_name = 'new_folder' if not os.path.exists(dir_name): os.makedirs...# 举例,使用Openpyxl库读取Excel文件并获取单元格数据的示例代码: from openpyxl import load_workbook wb = load_workbook('example.xlsx...# 举例,使用tkinter库制作一个简单的窗口的示例代码: import tkinter as tk window = tk.Tk() window.title('My Window') window.geometry...=False) # 打开Excel工作簿 wb = xw.Book('test.xlsx') # 选择要操作的工作表 sheet = wb.sheets['Sheet1'] # 写入数据 sheet.range...# 关闭工作簿和Excel应用程序 wb.save() wb.close() app.quit() PPT自动化 需要掌握python-pptx等库的使用,可以实现对PPT幻灯片的读取、修改、插入、删除等自动化操作
os模块是python系统与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录;相当于...获取当前目录的父目录字符串名:('..') os.makedirs('dirname1/dirname2') 可生成多层递归目录 os.removedirs('dirname1') 若目录为空,则删除,并递归到上一级目录...则删除,依此类推 os.mkdir('dirname') 生成单级目录;相当于shell中mkdir dirname os.rmdir('dirname') 删除单级空目录,若目录不为空则无法删除...即os.path.split(path)的第二个元素 os.path.exists(path) 如果path存在,返回True;如果path不存在,返回False os.path.isabs(path...) 如果path是绝对路径,返回True os.path.isfile(path) 如果path是一个存在的文件,返回True。
领取专属 10元无门槛券
手把手带您无忧上云