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参数表示的需要打开文件的相对路径(当前 ...
随机推荐
- JVM虚拟机垃圾回收(GC)算法及优缺点
一.什么是GC GC是jvm的垃圾回收,垃圾回收的规律和原则为: 次数上频繁收集新生区(Young) 次数上较少收集养老区(Old) 基本上不动永久区(Perm) 二.GC算法(分代收 ...
- How does Go kit compare to Micro?
Go kit - Frequently asked questions https://gokit.io/faq/ How does Go kit compare to Micro? Like Go ...
- C# 防止程序多开(重复开启)
Mutex(mutual exclusion,互斥)是 .Net Framework 中提供跨多个线程同步访问的一个类.它非常类似了 Monitor 类,因为他们都只有一个线程能拥有锁定.而操作系统能 ...
- Git恢复之前版本的两种方法reset、revert
实战 回退 1.删除之前的提交 git reset --hard id 推送到远程 git push -f [git log中确实删除了,但是拿到可以恢复] 2.不删除之前的提交 git revert ...
- redis中的小秘密和持久化小细节
https://www.jianshu.com/p/36c301ac87df 持久化的情况 https://www.cnblogs.com/wdliu/p/9377278.html 集群搭建 主从 ...
- CSS3 Flex Box 弹性盒子、弹性布局
目录 1. 概要 2. justify-content 属性 3. align-items 属性 4. flex-wrap 属性 5. align-content 属性 6. 居中 7. align- ...
- (二)SpringBoot应用运维脚本
SpringBoot应用运维脚本 一.获取PID 二.Kill命令 三.nohup命令 四.编写SpringBoot应用运维脚本 4.1全局变量 4.2编写核心方法 4.3Info方法 4.4stat ...
- JavaWeb——B/S,C/S结构,HTTP协议
B/S: 开发基于B/S结构项目:目前主要采用三种服务器端语言:JSP,PHP,ASP.NET. 这三种语言构成三种常用应用开发组合:JSP+Oracle组合.PHP+MySQL体系.以及ASP.NE ...
- DEDECMS:删除DEDE自带的织梦链方法
在include/taglib/flinktype.lib.php里删除掉如下代码: $dedecms = false; $dedecms->id = 999; $dedecms->typ ...
- java中的四种内部类使用(1)
内部类 (一) 概述 把类定义在另一个类的内部,该类就被称为内部类. 举例:把类Inner定义在类Outer中,类Inner就被称为内部类. class Outer { class Inner { } ...