python基础学习7-文件以及oa操作

  1. 操作文件步骤
    1. 打开/创建 变量名 = open(filename,mode,encoding)
    2. 操作 变量名.read() 变量名.write()
    3. 关闭 变量名.close()
  2. with open(...) as file:
    pass
  1. json模块
    1. json.dumps(obj) json(lst,ensure_ascli=False,indent=4) 防止中文乱码,和提供缩进美化
    2. json.loads(obj)
    3. json.dump(obj,file)
    4. json.load(file)
  2. os模块
    1. getcwd()
    2. listdir()
    3. mkdir()
    4. makedirs()
    5. rmdir()
    6. removedirs()
    7. chdir()
    8. walk()
    9. remove()
    10. rename()
    11. rename()
    12. stat()
    13. startfile()
    14. os.path.basename()
    15. os.path.dirname()
    16. os.path.isdir()
    17. os.path.isfile()
    18. os.path.abspath()
    19. os.path.exists()
posted @ 2024-02-15 21:47  月下云生  阅读(12)  评论(0)    收藏  举报