一.三元运算 三元运算又称三目运算,是对简单的条件语句的简写,如: 简单条件处理: if 条件成立: val = 1 else: val = 2 改成三元运算 val = 1 if 条件成立 else 2 二.智能检测文件编码 用第三方模块chardet 首先要安装chardet模块 ,用pip命令进行安装 chardet的用法 import chardet f = open("staff_table.txt","rb") data =f.read() f.clos
1.文件f.seek的应用 import time with open('access.log', mode='rb') as f: # 1.将指针跳到文件末尾 # f.read() # 错误 f.seek(0,2) while True: line=f.readline() if len(line) == 0: time.sleep(0.3) else: print(line.decode('utf-8'),end='') 2.文件修改的两种方式 with open('a.txt',mode=
C# 判断文件是否被占用的三种方法 using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.dll")] public static extern IntPtr _lopen(string lpPathName, int iReadWrite); [DllImport("kernel32.dll")] public static extern bool CloseHand