Python & file operation mode
Python & file operation mode
create/read/write/append mode
https://docs.python.org/3/library/functions.html#open
#!/usr/bin/env python3
# coding: utf8
__author__ = 'xgqfrms'
__editor__ = 'vscode'
__version__ = '1.0.1'
__copyright__ = """
Copyright (c) 2012-2050, xgqfrms; mailto:xgqfrms@xgqfrms.xyz
"""
"""
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-08-01
*
* @description
* @augments
* @example
* @link
*
*/
"""
print("write mode & close")
# append
# file = open("newfile.py", "w+a")
# file = open("newfile.py", "wa")
# ValueError: must have exactly one of create/read/write/append mode
# file = open("newfile.py", "ab+")
# TypeError: a bytes-like object is required, not 'str'
file = open("newfile.py", "a")
appended_length = file.write("appended text")
print("appended_length =", appended_length)
# appended_length = 13
file.close()
with open("newfile.py", "a") as file:
appended_length = file.write("\nappended text, again")
print("appended_length =", appended_length)
# appended_length = 21
file.close()
refs
Python 2, Abandoned
https://docs.python.org/2/library/functions.html#open
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
Python & file operation mode的更多相关文章
- python file operation
file.open(name[,mode[,buffering]]) 模式的类型有: r 默认只读 w 以写方式打开,如果文件不存在则会先创建,如果文件存在则先把文件内容清空(truncate ...
- Python:文件操作技巧(File operation)(转)
Python:文件操作技巧(File operation) 读写文件 # ! /usr/bin/python # -*- coding: utf8 -*- spath = " D:/dow ...
- Python File I/O
File is a named location on disk to store related information. It is used to permanently store data ...
- File Operation using SHFileOperation
SHFILEOPSTRUCT Original link: http://winapi.freetechsecrets.com/win32/WIN32SHFILEOPSTRUCT.htm Refere ...
- mysql数据库报错:InnoDB: Operating system error number 13 in a file operation
环境:centos6.5 x86_64 启动mysql发现日志报错(日志路径可以查看/etc/my.cnf的配置) 160722 10:34:08 [Note] Found 42570716 of 4 ...
- InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法
InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法 140628 8:10:48 [Note] Plugi ...
- Adobe ZXPInstaller 报错 Installation failed because of a file operation error.
1. Drag a ZXP file or click here to select a file. 拖放一个 zxp 文件或点击打开选择一个 zxp 文件来安装: 2. Installation f ...
- Python - File - 第十八天
Python File(文件) 方法 open() 方法 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OS ...
- [转]python file文件操作--内置对象open
python file文件操作--内置对象open 说明: 1. 函数功能打开一个文件,返回一个文件读写对象,然后可以对文件进行相应读写操作. 2. file参数表示的需要打开文件的相对路径(当前 ...
随机推荐
- LOJ10077
题目描述给出一个 N 个顶点 M 条边的无向无权图,顶点编号为 1∼N.问从顶点 1 开始,到其他每个点的最短路有几条. 输入格式第一行包含 2 个正整数 N,M,为图的顶点数与边数. 接下来 M行, ...
- Node 使用webpack编写简单的前端应用
编写目的 1. 使用 Node 依赖webpack.jQuery编写简单的前端应用. 操作步骤 (1)新建一个目录 $ mkdir simple-app-demo $ cd simple-app-de ...
- Redis 实战 —— 12. 降低内存占用
简介 降低 Redis 的内存占用有助于减少创建快照和加载快照所需的时间.提升载入 AOF 文件和重写 AOF 文件时的效率.缩短从服务器进行同步所需的时间(快照. AOF 文件重写在 持久化选项 中 ...
- Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警
Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警 一.添加依赖 1.1 Actuator 的 /prometheus端点 二.Prometheus 配置 部 ...
- socket套接字编程(1)——基本函数
TCP交互流程: 服务器:1. 创建socket:2. 绑定socket和端口号:3. 监听端口号:4. 接收来自客户端的连接请求:5. 从socket中读取字符:6. 关闭socket. 客户端:1 ...
- python中字符串的翻转(方法总结)
Python翻转字符串(reverse string), 一共包含5种方法, 其中第一种最简单, 即步长为-1, 输出字符串; 方法如下 5种方法的比较: 1. 简单的步长为-1, 即字符串的翻转(常 ...
- UML——构件图
宏观导图: 细节探究: 一.What 构件:是一个应用很广的名词,在建筑工程.机械工程.软件工程中等都有该概念.其实,说道底表达的都是一个意思.就像是标准化生产出来的零部件一样,具有可替换性.同质性, ...
- .Net Core 3.1浏览器后端服务(一) Web API项目搭建
一.前言 基于CefSharp开发的浏览器项目已有一段时间,考虑到后期数据维护需要Server端来管理,故开启新篇章搭建浏览器后端服务.该项目前期以梳理服务端知识为主,后期将配合CefSharp浏览器 ...
- ODS(Operational Data Store)定义
ODS(Operational Data Store)可操作的数据存储. 很多人对ODS究竟是什么有很多的困惑,ODS对于不同的人可以有不同的看法,我主要说说什么是最主流的定义.首先我们需要注意,OD ...
- P1908 逆序对——树状数组&离散化&快读快写の学习
题目简述: 对于给定的一段正整数序列,逆序对就是序列中 a_i>a_jai>aj 且 i<ji<j 的有序对. 输出序列中逆序对的数目. 知识补充: 树状数组: 这东西就是 ...