<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0"><channel><title>分类：文件操作 - GodOne</title><link>https://blog.godone.top/categories/%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C</link><atom:link href="https://blog.godone.top/categories/%25E6%2596%2587%25E4%25BB%25B6%25E6%2593%258D%25E4%25BD%259C/feed/categories/%25E6%2596%2587%25E4%25BB%25B6%25E6%2593%258D%25E4%25BD%259C.xml" rel="self" type="application/rss+xml"/><description>GodOne</description><generator>Halo v2.27.1</generator><language>zh-cn</language><lastBuildDate>Mon, 16 Nov 2026 13:50:18 GMT</lastBuildDate><item><title><![CDATA[Python文件操作-缓存区]]></title><link>https://blog.godone.top/archives/%E7%BC%93%E5%AD%98%E5%8C%BA</link><description><![CDATA[<img src="https://blog.godone.top/plugins/feed/assets/telemetry.gif?title=Python%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C-%E7%BC%93%E5%AD%98%E5%8C%BA&amp;url=/archives/%E7%BC%93%E5%AD%98%E5%8C%BA" width="1" height="1" alt="" style="opacity:0;">当我们调用write方法来往文件内写入数据时，数据不会立刻存入文件内，而会先存入缓存区，只有调用close和flush等方法才会把缓存区内的数据写入文件内 flush方法 def demo_2(): fw = open('/tmp/123.txt', mode='w') fw.wri]]></description><guid isPermaLink="false">/archives/%E7%BC%93%E5%AD%98%E5%8C%BA</guid><dc:creator>GodOne</dc:creator><category>文件操作</category><category>Python</category><pubDate>Sun, 1 Nov 2026 17:12:02 GMT</pubDate></item><item><title><![CDATA[Python文件操作-write写]]></title><link>https://blog.godone.top/archives/write%E5%86%99</link><description><![CDATA[<img src="https://blog.godone.top/plugins/feed/assets/telemetry.gif?title=Python%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C-write%E5%86%99&amp;url=/archives/write%E5%86%99" width="1" height="1" alt="" style="opacity:0;">write方法 写文本字符串 def demo_1(): fw = open('/tmp/aaa.txt', mode='w') fw.write('Hello World !!!\n') fw.close() 写入多行 def demo_1(): fw = ope]]></description><guid isPermaLink="false">/archives/write%E5%86%99</guid><dc:creator>GodOne</dc:creator><category>文件操作</category><category>Python</category><pubDate>Sun, 1 Nov 2026 17:12:02 GMT</pubDate></item><item><title><![CDATA[Python文件操作-with open]]></title><link>https://blog.godone.top/archives/with-open</link><description><![CDATA[<img src="https://blog.godone.top/plugins/feed/assets/telemetry.gif?title=Python%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C-with%20open&amp;url=/archives/with-open" width="1" height="1" alt="" style="opacity:0;">with open 可以快捷的打开文件，并且不再需要手动关闭文件，简化了文件的操作 with open('/etc/password', mode='r') as fr: fr.readline()]]></description><guid isPermaLink="false">/archives/with-open</guid><dc:creator>GodOne</dc:creator><category>文件操作</category><category>Python</category><pubDate>Sun, 1 Nov 2026 17:12:02 GMT</pubDate></item><item><title><![CDATA[Python文件操作-read读]]></title><link>https://blog.godone.top/archives/read%E8%AF%BB</link><description><![CDATA[<img src="https://blog.godone.top/plugins/feed/assets/telemetry.gif?title=Python%E6%96%87%E4%BB%B6%E6%93%8D%E4%BD%9C-read%E8%AF%BB&amp;url=/archives/read%E8%AF%BB" width="1" height="1" alt="" style="opacity:0;">read方法 读取整个文件 def read1(): passwd = open('/etc/passwd', 'r') text = passwd.read() passwd.close() 读取指定个字符 读取文本时会随之移动读取指针，如果要重置指针可用 .close()方法]]></description><guid isPermaLink="false">/archives/read%E8%AF%BB</guid><dc:creator>GodOne</dc:creator><category>文件操作</category><category>Python</category><pubDate>Sun, 1 Nov 2026 17:12:02 GMT</pubDate></item></channel></rss>