• 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)
  • 相关阅读:
    移动web基础
    CSS3
    HTML5新属性
    CSS3初体验之伪元素选择器
    HTML5+CSS3day_01
    CSS补充
    CSS_day02
    CSS_day01
    HTML_day02
    HTML_day01
  • 原文地址:https://www.cnblogs.com/peace-ful/p/14243508.html
Copyright © 2020-2023  润新知