惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
L
LangChain Blog
A
About on SuperTechFans
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
博客园 - 司徒正美
Scott Helme
Scott Helme
K
Kaspersky official blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
腾讯CDC
Recorded Future
Recorded Future
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
G
GRAHAM CLULEY
Security Latest
Security Latest
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
雷峰网
雷峰网
T
The Exploit Database - CXSecurity.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
T
The Blog of Author Tim Ferriss
D
Docker
S
Security Affairs
F
Full Disclosure
Know Your Adversary
Know Your Adversary
N
News and Events Feed by Topic
N
News and Events Feed by Topic
T
Tor Project blog
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Microsoft Security Blog
Microsoft Security Blog
Simon Willison's Weblog
Simon Willison's Weblog
Recent Announcements
Recent Announcements
博客园_首页
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security @ Cisco Blogs

博客园 - soulsjie

一种在winfrom窗体中显示计算公式的解决方案 winform窗体DataGridView合并单元格处理 C#GDI+阴影笔刷样式HatchStyle探讨 C#代码混淆工具ConfuserEx的使用 Aspose.Words在指定位置插入图片、调整图片大小 C#获取对象实体的键值对信息 C#将Winform上的TextBox和ComBox的值导入和导出 C#使用Aspose.Words将Spread表格插入到Word中 C# Aspose.Words将word中自定义的标签进行替换 C# 将项目资源文件保存到磁盘上 SqlSugar数据库辅助类 使用存储过程备份MS SQLServer数据库 案例3:JAVA GUI 随机点名程序 案例2:JAVA GUI 简易计算器 ArcGIS JS API 添加要素图层 点击时获取图层属性 ArcGIS JS API 将天地图设置为底图 HTML5PLUS实现类似右侧弹出菜单 SqlSugar各数据库连接串 案例1:JAVAGUI用户管理
Python文件操作基础方法
soulsjie · 2023-01-18 · via 博客园 - soulsjie
import os
import shutil

#创建文件
def CreateFile(filename):
    f=open(filename,mode='a',encoding='utf-8')
    f.close()
    print("-------文件创建成功--------")

#写入文件内容
def AppendFileContent(filename,content):
    f = open(filename, mode='a', encoding='utf-8')
    f.write(content)
    f.close()
    print("-------写入文件内容成功--------")

#读取文件内容
def ReadFile(filename):
    f = open(filename, mode='r', encoding='utf-8')
    for line in f.readlines():
        print(line)
    f.close()

#删除文件
def DelFile(filename):
    print("-------删除文件--------")
    os.remove(filename)
    print("-------删除文件成功--------")

#复制文件
def Copyile(filename,newFilename):
    shutil.copy(filename, newFilename)
    print("-------复制文件成功--------")

#文件重命名
def ReNameFile(filename,newFilename):
    os.rename(filename, newFilename)
    print("-------文件重命名成功--------")

#创建文件
CreateFile("ces.txt")
#往文件中追加内容
AppendFileContent("ces.txt","测试文本内容张三\n")
#读取文件
ReadFile("ces.txt")
#复制文件
Copyile("ces.txt","ces2.txt")
#文件重命名
ReNameFile("ces.txt","ces3.txt")
#最后删除文件
DelFile("ces2.txt")
DelFile("ces3.txt")