数据开发_Python读取文件

os 模块

是Python标准库中提供的与操作系统交互的模块,提供了访问操作系统底层的接口,里面有很多操作系统的函数
 os.walk
 os.listdir()
 os.stat()
 os.mkdir
 os.rename
 os.remove('pass.xls')#删除文件
 os.path.exists
 os.path.isfile
 os.path.isdir
 os.path.islink
 os.path.splitext
 os.path.split
 os.path.join
 os.path.basename   os.path.splitext(path) os.path.splitext()更多的运用在了搜索文件路径(path)和文件的扩展名(ext)
 os.path.dirname
 os.path.getsize()
 os.path.getmtime

sys 模块

负责程序与Python解释器的交互
sys.argv #命令行参数List,第一个元素是程序本身路径
sys.getdefaultencoding()

读写文件

with open() as f:
    pass

f = open('somefile.txt', 'rt')
data = f.read()
f.close()

文件权限 元数据 编码

 文件描述符
 UnicodeEncodeError
 其他模块: tempfile  
   shutil 模块

其他类似

通过串行端口读写数据 pySerial包   涉及到串口的I/O都是二进制模式的。因此,确保你的代码使用的是字节 
超时,控制流,缓冲区刷新,握手协议
 使用模式为 rb 或 wb 的 open() 函数来读取或写入二进制数据
   所有返回的数据都是字节字符串格式的,而不是文本字符串 索引和迭代动作返回的是字节的值而不是字节字符串
   字长和字节顺序(高位优先和低位优先)

常用正则

不以“select *”开头的行替换为空行
    ^(?!select *)(.*)
删除空行
   ^(s*)
 或者  ^(s*)

做事层次和阶段

 预期和预判   实际情况   复盘初衷和行为 行为依据 以及效果
 理论和实际  实际的效果   目标与效果
原文地址:https://www.cnblogs.com/ytwang/p/14302004.html