编码 IO第一次复习

'''
#插入排序
def insertSorted(list):
    for i in range(1,len(list)):#取数
        temp = list[i]
        flag = False
        for j in range(i-1,-1,-1):#取i左面的数 步长-1
            if list[j] > temp:
                list[j+1] = list[j]
            else:
                list[j+1] = temp
                flag = True
                break
        if not flag:
            list[0] = temp
a = [5,8,2,6,7]
insertSorted(a)
print(a)
'''
"""
ASCII(0-127)                                 8
ANSI(拉丁文)                                 8
GB2312(7000) 前八位和后八位>127            16
GBK(gb2312,2万多)前八位>127                  16
UNICODE                                      16
UTF-8(推荐)                                  8 or 24

py2中string  (str,unicode(u))   str+unicode     str-->unicode
py3中string (str,bytes(b))    str+bytes x

I-input  输入       读取数据
O-output 输出       写入数据
open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True)
flush--清空缓存
"""
'''
mode:
    r  只读  指针默认文件开头  默认模式
    rb 二进制打开文件只读 指针默认文件开头 默认模式
    --r+ 读写 指针放在文件开头
    rb+ 二进制打开文件读写 指针默认文件开头
    w  仅写入  存在即覆盖  不存在即创建新文件
    wb 以二进制打开仅写入 存在即覆盖 不存在即创建新文件
    --w+ 读写 存在即覆盖 不存在即创建新文件
    wb+ 二进制打开读写 存在即覆盖 不存在即创建新文件
    a 追加 存在即指针放在文件结尾(新内容写在已有内容之后)
            不存在即创建新文件写入
    ab 二进制打开文件追加  存在则指针放在文件结尾追加
            不存在即创建新文件写入
    a+ 读写 文件存在则指针放在文件结尾追加
            文件不存在即创建新文件
    ab+ 二进制打开文件追加 存在指针则放在文件结尾
            文件不存在即创建新文件写入
    
'''
#---------------IO-----------------
'''
#r---string
fio = open("a.txt",encoding = "utf8",mode = "r")
print(fio.read())
'''

'''
fio = open("a.txt",encoding = "utf8",mode = "w")
print(fio.write("书山有路勤为径,学海无涯苦作舟"))
'''

'''
#rb--bytes字符串
fio = open("a.txt",mode = "rb")
print(fio.read())
'''

"""
#r+---读写 string
fio = open("a.txt",mode = "r+",encoding = "utf-8")
#print(fio.read())
fio.write("dscxdc")
"""

'''
fio = open("a.txt",mode = "rb+")
print(fio.read())
fio.write(b"dwdffe")
'''

'''
fio = open("b.txt",mode = "w",encoding = "utf8")
fio.write("I will go home!")
fio.write("\nByeBye!")
fio.write("\nasdfg")
'''

'''
fio = open("b.txt",mode = "r",encoding = "utf8")
#print(fio.readline())
data = fio.readline()
while data != "":
    print(data)
    data = fio.readline()
'''

'''
fio = open("b.txt",mode = "r",encoding = "utf8")
list = fio.readlines()
print(len(list))
print(list)
'''

'''
fio = open("b.txt",mode = "r",encoding = "utf8")
list = fio.readlines()
for index,line in enumerate(list):
    if index == 9:
        print("------分割线------")
        continue
    print(line.strip())
'''

'''
fio = open("b.txt",mode = "r",encoding = "utf8")
count = 0
for line in fio:
    if count == 9:
        print("-----分割线-----")
        count += 1
        continue
    else:
        print(line.strip())
        count += 1
'''

'''
#tell  光标所在位置--字节个数
#seek(0) 光标回到原点
fio = open("b.txt",mode = "r",encoding = "utf8")
print(fio.tell())
for line in fio:
    print(line.strip())
print(fio.tell())
'''

'''
#进度条 
#truncate()截断
import sys,time
for i in range(101):
#while True:
    sys.stdout.write("#")
    sys.stdout.flush()
    time.sleep(0.1)
'''

'''
#替换
fio = open("b.txt",mode = "r",encoding = "utf8")
fio_new = open("b.bak",mode = "w",encoding = "utf8")
for line in fio:
    if "qwertyuiop" in line:
        line = line.replace("qwertyuiop","asdfg")
    fio_new.write(line)
fio.close()
fio_new.close()
'''
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值