CodeHelper CodeHelper
首页
JavaScript
PHP
Python
Git速查表 (opens new window)
博客 (opens new window)
首页
JavaScript
PHP
Python
Git速查表 (opens new window)
博客 (opens new window)
  • 开始

    • 使用
  • 函数方法

    • 字符串
    • 日期时间
    • 文件操作
      • 往一个文件里写内容
    • 请求
    • pandas操作Excel
    • SQL语句
    • ...
目录

文件操作

# 往一个文件里写内容

# mode='a': 追加
def wFileContent(path='', content='', mode='a'):
    if len(path) == 0:
        print("path不存在", "\n")
        return

    fx = None
    try:
        fx = open(file=path, mode=mode, encoding='utf-8')  # 打开文件

        if isinstance(content, list):
            content = "".join('%s' % strItem for strItem in content)
        elif isinstance(content, tuple):
            content = "".join('%s' % strItem for strItem in content)
        elif isinstance(content, str):
            content = content

        content += "\n"
        fx.write(content)
        fx.close()
    except Exception as e:
        print("文件操作失败", "\n")
        exit()
上次更新: 2022/08/23, 18:58:25
日期时间
请求

← 日期时间 请求→

Theme by Vdoing | Copyright © 2022-2023 CodeHelper
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式