Python 模块
文章平均质量分 52
Python 模块
刘长栋
这个作者很懒,什么都没留下…
展开
-
import os总结
import os总结转自 学不会的程序员一、os.path.abspath(path)返回path的绝对路径os.path.abspath("train.py")'E:\\my_project\\darknet\\darknet-master\\keras-yolo3\\keras-yolo3-master\\train.py'二、os.path.split(path)将path分割成目录和文件名并以元组方式返回os.path.split("E:\\my_project\\darkne转载 2021-10-27 21:56:37 · 254 阅读 · 0 评论 -
Python os 路径下文件和文件夹
1 键盘输入一个路径,2 统计该路径下的文件夹和文件数量,并列出3 统计改文件夹下包含的 .exe的文件数量,注意不区分大小写import osprint(os.path) #改变 路径for i in os.scandir(): # 历遍路径 print(i)path=input("请输入你要查询的路径:")# path="c:\windows"os.chdir(path) #改变当前 路径dir_list=[]file_list=[]for i in os.sc原创 2021-11-07 23:21:52 · 404 阅读 · 0 评论 -
Python os 模块 文件查找 路径 glob 文件大小,文件时间os.stat.(path).st_size st_mtime
1 文件大小 os.stat(文件).st_size /1024/1024 变兆2 有关时间2.1 现在 datetime.datetime.now()2.2 文件时间戳 os.stat(文件).st_mtime2.3 格式化时间戳 datetime.datetime.fromtimestamp(os.stat(file).st_mtime)#--*coding:utf-8*--# 1 键盘输入一个路径# 2 搜索改路径下 文件大小超过 50m的zip文件# 3 搜原创 2021-11-08 14:58:56 · 854 阅读 · 0 评论 -
Python 文件 os.walk glob 查看文件夹内容
1 os.walk("./")"./" 当前目录"../" 包括上层目录 import os for dirpath,dirnames,files in os.walk("./"): # 当前目录下文件信息 包括上层目录("../") print(dirpath,dirnames,files)../Day6\Word [] ['070-word.py', '体温记录单.docx', '居住证明.docx', '当前疫情重点地区.docx'] ../ 表示上层目录 Day6\原创 2021-11-08 14:46:58 · 271 阅读 · 0 评论 -
Python 模块 积累
1. import random 随机数 # -*- coding: UTF-8 -*-import randomprint( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 print( random.random() ) # 产生 0 到 1 之间的随机浮点数print( random.uniform(1.1,5.4) ) # 产生 1.1 到 5.4 之间的随机浮点数,区间可以不是整数prin原创 2021-11-09 09:15:45 · 418 阅读 · 0 评论 -
Python收集小模块
1.当前目录 “./” 文件夹内所有文件 for 路径,目录名,文件名 in os.walk("./")2. 带路径 改名os.rename(路径+"/"+文件.name,新名字)for 路径,目录名,文件s in os.walk("./"): # 当前目录 for 文件 in os.scandir(路径): os.rename(路径+"/"+文件.name,新名字)3. 一个文件夹 复制到另一个文件夹 shutil.copytree#--*coding:utf-8*--i原创 2021-11-09 22:45:03 · 402 阅读 · 0 评论 -
Python Pandas 详细 查看 处理 汇总
参考:https://www.runoob.com/pandas/pandas-tutorial.html1 . 安装 pip install pandas2 . SeriesSeries 由索引(index)和列组成pandas.Series( data, index, dtype, name, copy) import pandas as pd创建import pandas as pd## 自动序号print(pd.Series([3,0.5,"liucd"]))## 手动序号原创 2021-11-02 22:56:17 · 518 阅读 · 0 评论