首页 > 编程语言 >python_xecel

python_xecel

时间:2022-11-13 18:37:00浏览次数:40  
标签:__ name python xecel file Path test path

  • 移动并重命名工作簿
 1 from pathlib import Path  # 导入pathlib模块的path类
 2 import time
 3 
 4 # Press the green button in the gutter to run the script.
 5 if __name__ == '__main__':
 6     data = time.strftime('%y-%m-%d %H:%M:%S')
 7 
 8     old_file_path = Path('D:\\demo\\python\\test_excel\\file_from\\test.xlsx')        # 这里的Path,等价于os.path,join();参考第10行代码
 9     new_file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
10     # test_path = Path('D:', 'demo', 'python', 'test_excel', 'file_from', 'test.xlsx')
11     old_file_path.rename(new_file_path)                               # 剪切并重命名
12 
13     if new_file_path.is_file():
14         print(f'{data}:{old_file_path} rename successed')
  •  解析工作簿的路径信息
 1 from pathlib import Path  # 导入pathlib模块的path类
 2 import time
 3 
 4 # Press the green button in the gutter to run the script.
 5 if __name__ == '__main__':
 6     data = time.strftime('%y-%m-%d %H:%M:%S')
 7     file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
 8     # 解析工作簿的路径信息
 9     path = file_path.parent
10     # 打印文件所在路径
11     print(f'文件路劲----:{path}')
12     file_name = file_path.name
13     # 打印文件名字
14     print(f'文件名为----:{file_name}')
15     suffix = file_path.suffix
16     # 打印文件后缀名
17     print(f'文件后缀名为----:{suffix}')
  •  提取文件夹内所有工作簿的文件名
 1 from pathlib import Path  # 导入pathlib模块的path类
 2 
 3 # Press the green button in the gutter to run the script.
 4 if __name__ == '__main__':
 5     folder_path = Path('D:\\demo\\python\\test_excel\\file_to')
 6     file_list = folder_path.glob('*.xlsx')
 7     print(f'file_list----:{file_list}')
 8     lists = []
 9     for test in file_list:
10         file_name = test.name
11         lists.append(file_name)
12     print(f'lists----:{lists}')

 

标签:__,name,python,xecel,file,Path,test,path
From: https://www.cnblogs.com/xiaopangyu/p/16886474.html

相关文章

  • python 嗅探
    importtimeimportreimportosfromscapy.allimport*fromthreadingimportThread#定义变量函数wifi='RNDIS'rtable=os.popen('routeprint').read()......
  • Python 处理Protobuf协议
    安装protobuf使用HomeBrew安装Protobuf:brew install protobuf查看是否安装成功protoc --version进入文件路径命令行执行protoc--python_out=././HT_mo......
  • Python正则表达式入门
    Python正则表达式入门文章目录​​Python正则表达式入门​​​​1、在Python中使用正则表达式​​​​2、最基础正则表达式​​​​3、正则匹配函数​​​​正则表达式的字......
  • 学习python-Day87
    一、前台首页组件编写需要创建4个组件HomeView.vue页面组件Header.vue头部组件Banner.vue轮播图组件Footer.vue尾部组件1.HomeView.vue<template><di......
  • Python爬虫之简单爬虫之爬取英雄联盟官网的英雄的皮肤
    Python爬虫之简单爬虫之爬取英雄联盟官网的英雄的皮肤文章目录​​Python爬虫之简单爬虫之爬取英雄联盟官网的英雄的皮肤​​​​背景:LOL这款游戏有着大量的玩家,这个游戏里......
  • Python爬虫之爬取绝对领域美女图片
    Python爬虫之爬取绝对领域美女图片第一步:导入模块:importrequestsfromlxmlimportetree第二步:定义函数:defget_url(start_url):response=requests.get(start_url)d......
  • Python之递归函数与装饰器
    Python之递归函数与装饰器文章目录​​Python之递归函数与装饰器​​​​递归的含义:​​​​python中的时间模块​​​​装饰器​​递归函数在函数内部,可以调用其他函数。如......
  • Python之selenium的打开浏览器的二种方式
    Python之selenium的打开浏览器的二种方式文章目录​​Python之selenium的打开浏览器的二种方式​​​​第一步我们要先按照selenium:​​​​第一种打开方式:​​​​第二种......
  • Python如何使用XPath对HTMl内容解析,,玩转XPath
    Python如何使用XPath对HTMl内容解析文章目录​​Python如何使用XPath对HTMl内容解析​​​​HTMl内容解析​​​​HTML基础:​​​​什么是XPath:​​​​lxml的安装​​​​......
  • (Python)简易通讯录
    问题描述:将用户输入用逗号分隔的一系列人名作为键,用户输入的逗号分隔的手机号作为值,创建字典MyDict,输入一个正整数n,你将被要求读入n个输入(输入形式如下所示),每得到一......