zoukankan      html  css  js  c++  java
  • python学习-文件操作

    # 打开并创建文件
    # my_file = open(r"D:pythonCode7day_codeindex.html", "w", encoding="utf-8")
    # #
    # my_file.write("<title>我的文件</title>")
    # my_file.close()

    # 一行
    # content = my_file.readline()
    # content = my_file.readline()

    # 所有行
    # content = my_file.readlines()
    # print(content)
    # my_file.close()


    # 打开并创建文件
    # my_file = open(r"C:UsersAdministratorDesktopindex.html", "w", encoding="utf-8")
    # #
    # my_file.write("<title>我的文件</title>")
    # my_file.close()

    # 文件备份
    # my_file =open("index.html", "r", encoding="utf-8")
    # my_newFile = open("index[备份].html", "w", encoding="utf-8")
    # content = my_file.read()
    # my_newFile.write(content)
    # my_file.close()
    # my_newFile.close()

    # 大文件怎么备份
    # my_file = open(r"C:UsersAdministratorDesktopday02day021-视频2-今日内容介绍.itfeat", "rb")
    # my_newFile = open("v[备份].itfeat", "wb")
    # while True:
    # content = my_file.read(1024)
    # my_newFile.write(content)
    # if len(content) == 0:
    # break
    # my_file.close()
    # my_newFile.close()

    # 文件操作
    # import os
    # os.rename("index.html", "web_info.html")
    # os.rmove("v[备份].itfeat")
    # path = os.mkdir(r"C:UsersAdministratorDesktopwo")
    # os.getcwd()
    # os.chdir("../")
    # os.listdir(r"C:UsersAdministratorDesktop")
    # os.rmdir(r"C:UsersAdministratorDesktopwo")

    # path = r"C:UsersAdministratorDesktopwo"

    # 创建 五个文件夹
    # for x in range(1, 6):
    # with open(path + "\%d.txt" % x, "w", encoding="utf-8") as my_file:
    # my_file.write("2021/1/6 %d" % x)

    # 删除 文件
    # import os
    # os.chdir(path)
    # for name in os.listdir():
    # os.remove(name)


    # 修改文件名
    # import os
    # os.chdir(path)
    # for name in os.listdir():
    # os.rename(name, "奇技课堂--"+ name)
  • 相关阅读:
    vs2017 离线安装。
    c# begin & end.
    vc++ 下的WaitForSingleObject
    c# 工厂模式 ,委托 ,事件。
    微信分享 andriod studio
    mac osx 10.9 ftp server端口
    win32 调用多媒体函数PlaySound()
    [汇编语言]-第九章 在屏幕中间分别显示绿底红色,白底蓝色字符串"welcome to masm!"
    [汇编语言]-第九章 jcxz,loop指令,转移位移的意义
    补码
  • 原文地址:https://www.cnblogs.com/peace-ful/p/14243508.html
Copyright © 2011-2022 走看看