Safe open function
Project description
Introduction
Resolved Issue: When reading a file, the inadvertent use of "w" mode will erase the original file's contents.
Install
pip install safe_open
How to use
from safe_open import safe_open
with safe_open("test.txt", "w") as f:
f.write("Hello, World!") # 正常写入
with safe_open("test.txt", "r") as f:
content = f.read() # 正常读取
with safe_open("test.txt", "w") as f: # OSError: file mode error: cannot read in write mode
content = f.read() # 异常读取
with safe_open("test.txt", "r") as f: # OSError: file mode error: cannot write in read mode
content = f.write() # 异常写入
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
safe_open-0.2.1.tar.gz
(2.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file safe_open-0.2.1.tar.gz.
File metadata
- Download URL: safe_open-0.2.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
150bc7775ec1a110d968f5982d5a18f7aa97ef6263e0cf1af98cb911bc8e4020
|
|
| MD5 |
c6aab7ef775b6438def894ba440fe714
|
|
| BLAKE2b-256 |
463b9b9086d698e1dd7d9194dd96af8f6ae7900cd896460c16abc8058aa9bfa4
|
File details
Details for the file safe_open-0.2.1-py3-none-any.whl.
File metadata
- Download URL: safe_open-0.2.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8b417c9cd7ff02e6825adac674ee54849ae40f3abf70f590bb97faf06375b9f
|
|
| MD5 |
602bf07831233775f464a65d2347e55b
|
|
| BLAKE2b-256 |
00ac91542295422996f69965eb8702e8981f40b1118832525c62f0e861b1aa8e
|