mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-22 22:37:37 +08:00
🌠也许,大家的测试环境都是*nix?
Update file.py
This commit is contained in:
parent
ab89cd1c72
commit
80c6875567
@ -1,10 +1,12 @@
|
|||||||
import aiofiles
|
import aiofiles
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
async def write_file(
|
async def write_file(
|
||||||
file_path: str,
|
file_path: str | Path,
|
||||||
content: str | bytes,
|
content: str | bytes,
|
||||||
mode: str = "w"
|
mode: str = "w",
|
||||||
|
**kws,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
写入文件
|
写入文件
|
||||||
@ -13,11 +15,15 @@ async def write_file(
|
|||||||
file_path: 文件路径
|
file_path: 文件路径
|
||||||
content: 内容
|
content: 内容
|
||||||
"""
|
"""
|
||||||
async with aiofiles.open(file_path, mode) as f:
|
async with aiofiles.open(file_path, mode, **kws) as f:
|
||||||
await f.write(content)
|
await f.write(content)
|
||||||
|
|
||||||
|
|
||||||
async def read_file(file_path: str, mode: str = "r") -> str:
|
async def read_file(
|
||||||
|
file_path: str | Path,
|
||||||
|
mode: str = "r",
|
||||||
|
**kws,
|
||||||
|
) -> str:
|
||||||
"""
|
"""
|
||||||
读取文件
|
读取文件
|
||||||
Args:
|
Args:
|
||||||
@ -25,5 +31,5 @@ async def read_file(file_path: str, mode: str = "r") -> str:
|
|||||||
mode: 读取模式
|
mode: 读取模式
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
async with aiofiles.open(file_path, mode) as f:
|
async with aiofiles.open(file_path, mode, **kws) as f:
|
||||||
return await f.read()
|
return await f.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user