Menu

python基础4之集合和文件操作

重修课程day6(python基础4之集结和文件操作),

一 字典属性方法补充

key是不变的花色,字典能便捷寻觅,基于哈希索引

不可变类型 int  bool  str  tuple  可变类型:list  dict  set

 1 clear  :清空

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.clear()
# print(d)    #清空

 2 Cory:拷贝

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# a=d.copy()
# print(a)     #拷贝

 3 fromkeys:生成叁个字典,类上边包车型大巴三本性质方法

a=dict.fromkeys(['k1','k2','k3'],[1,2])
print(a)

 4 pop  :删除

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.pop('k1')
# print(d)         #按照key删除

 5 popitem  : 删除全体因素

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.popitem()
# print(d)    #删除整个键值对

 6 setdefault:只增多不改换

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.setdefault('k3','v3')
# print(d)   #添加元素

 7 update :存在的话跟新,未有就能够增进

# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.update({'k2':'v3','k3':'v2'})
# print(d)    #添加,如果key存在,修改value值

二 集合以及集聚的功能

 集合是四个不设有重新的值,並且照旧冬辰的。

 1 add :增添不容许再一次

# a={'fang','jie','lei','dong','tao'}
# a.add('qq')      #添加,如果集合里面有,就不会添加
# print(a)

 2 clear :清空

# a={'fang','jie','lei','dong','tao'}
# a.clear()      #清空
# print(a)

 3 copy :拷贝

# a={'fang','jie','lei','dong','tao'}
# b=a.copy()    #拷贝
# print(b)

 4 difference :差集只存在四个会晤的

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a - b)   #差集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.difference(b))    #查看差集

 5 difference_update:找差集并立异

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.difference_update(b)
# print(a)   #查找差集并更新

 6 symmetric_difference :找对称差集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a ^ b)   #对称差集
#
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.symmetric_difference(b))   #查看对称差集

 7 symmetric_difference_update:  着对称差集并革新

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.symmetric_difference_update(b)
# print(a)        #查找对称差集并更新

 8 discard :依据目的删除

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.discard('jie')
# print(a)      #删除

 9 intersection:交集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a & b)   #交集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.intersection(b))   #交集

 10 intersection_update:交集并立异

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.intersection_update(b)
# print(a)      #查找并集并更新

 11 union  :并集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a | b)    #并集
#
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.union(b))            #并集

 12 isdisjoint :判定是或不是无交集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.isdisjoint(b))     #判断是否无交集

 13 iscubset :推断是还是不是是子集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','jie'}
# print(b.issubset(a))   #判断b是不是a的子集

 14 issuperset :剖断是还是不是是父集

# a={'fang','jie','lei','dong','tao'}
# b={'fang','jie'}
# print(a.issuperset(b))    #判断a是不是b的父集

 15 pop 随机删除

# a={'fang','jie','lei','dong','tao'}
# a.pop()
# print(a)    #随机删除

 16 remove :钦赐删除

# a={'fang','jie','lei','dong','tao'}
# a.remove('fang')
# print(a)      #指定元素删除

 17 update :更新

# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.update()
# print(a)    #更新

 18 len :长度

# a={'fang','jie','lei','dong','tao'}
# print(len(a))

set一般的事态下,集合属性前面必得放会集,属性前面能够放大肆的数据类型,集结里面包车型大巴值是不可能变得。{}暗许是字典,想要创制群集就是set()

三 文件操作

 文件的常用方法右

  1,r(read):读取文件,只好读取,不可能别的操作;
 r+:不光是能够读取,并且还足以写入,r+是先读取再写入

  2 ,w(write):写入文件,只好写入;   
w+:可是能够写入,何况还足以写入过后再去读取。

  3 ,a(append):追加内容,只好增添;  a+:追加过后仍是能够读取文件

# #以bytes类型写入文件
# a=b'\xe4\xbd\xa0\xe4\xb8\xaa\xe5\xa4\xa7\xe5\x82\xbb\xe5\x8f\x89\r\n\xe9\x82\xa3\xe4\xba\xba\xe5\xb0\xb1\xe6\x98\xaf\xe4\xbd\xa0'
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','wb')
# b=f.write(a)
# f.close()
#
# #以w覆盖的方式写入
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w',encoding='utf-8')
# b=f.write('dsdf')
# f.close()

#
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd')
# f.seek(0)       #seek()指定光标的位置
# a=f.read()
# f.close()
# print(a)



# a#追加的方式添加
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','a',encoding='utf-8')
# b=f.write('dsdf')
# f.close()

##追加过后再读取
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','a+',encoding='utf-8')
# b=f.write('dsdf')
# f.seek(0)
# a=f.read()
# f.close()
# print(a)


# #以bytes类型读取
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='rb')
# a=f.read()
# f.close()
# print(a)
#
# #以utf-8格式读取
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r',encoding='utf-8')
# a=f.read()
# f.close()
# print(a)

##先读取在追加
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r+',encoding='utf-8')
# a=f.read()
# f.seek(3)
# f.write('jie')
# f.close()
# print(a)
#

 文件下的品质操作:

  1 read:读取文件

# with open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','r',encoding='utf-8')as f :
#     obj=f.read()
# print(obj)

  2 write:写入文件

#格式2 :
# with open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w',encoding='utf-8')as f :
#     f.write('yi')

  3 seek:调度光标的职位

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd')
# f.seek(0)       #seek()指定光标的位置
# a=f.read()
# f.close()
# print(a)

  4 tell:读取光标的岗位

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# a=f.tell()   #查找光标的位置
# print(a)

  5 writable:是不是可写

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# a=f.writable()   #判断是否可写
# print(a)

  6 readable:是不是可读

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readable()   #判断是否可读
# f.close()
# print(a)

  7 close:关闭文件

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# f.close()      #关闭

  8 flush:刷到硬盘

# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r+',encoding='utf-8')
# a=f.read()
# f.seek(3)
# f.flush()      #flush 刷到硬盘
# f.write('jie')
# f.close()
# print(a)

  9 fileno:文件对象

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# a=f.fileno()             #文件对象
# f.close()     
# print(a)

  10 isatty :判别是不是输出设备

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.isatty()      #判断是否是输出设备
# f.close()
# print(a)

  11 readline:读取一行内容

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readline()   #只读取整行
# f.close()
# print(a)

  12 seekable:决断是或不是可安装指针

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# a=f.seekable()    #判断是否可设置指针
# print(a)

  13 truncate : 光标后边的剧情不要了,只要光标后面的从头到尾的经过

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# f.truncate(5)       #指定光标的位置,然后再保留光标前面的内容是删除光标后面的内容
# f.close()

  14 readlines:读取全数的开始和结果,然后一块监督带领内部存款和储蓄器

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readlines()      #全部读取,返回是列表,元素字符串
# f.close()
# print(a)

 python2 中的xreadlines就也等于python3中的for  line  in  f:

# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# for line in f:
#     print(line)
# f.close()


字典属性方法补充 key是不改变的连串,字典能飞速搜索,基于哈希索引
不可变类型 int b…

 

 

一 字典属性方法补充

key是不改变的品种,字典能便捷寻找,基于哈希索引

不得变类型 int  bool  str  tuple  可变类型:list  dict  set

 1 clear  :清空

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.clear()
# print(d)    #清空

 2 Cory:拷贝

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# a=d.copy()
# print(a)     #拷贝

 3 fromkeys:生成贰个字典,类上边包车型地铁三个天性方法

1
2
a=dict.fromkeys(['k1','k2','k3'],[1,2])
print(a)

 4 pop  :删除

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.pop('k1')
# print(d)         #按照key删除

 5 popitem  : 删除全体因素

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.popitem()
# print(d)    #删除整个键值对

 6 setdefault:只增多不修改

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.setdefault('k3','v3')
# print(d)   #添加元素

 7 update :存在的话跟新,未有就能够助长

1
2
3
4
5
6
# d={
#     'k1':'v1',
#     'k2':'v2'
# }
# d.update({'k2':'v3','k3':'v2'})
# print(d)    #添加,如果key存在,修改value值

二 会集以及汇集的机能

 集结是五个不设有重复的值,并且仍旧冬天的。

 1 add :增添不容许再一次

1
2
3
# a={'fang','jie','lei','dong','tao'}
# a.add('qq')      #添加,如果集合里面有,就不会添加
# print(a)

 2 clear :清空

1
2
3
# a={'fang','jie','lei','dong','tao'}
# a.clear()      #清空
# print(a)

 3 copy :拷贝

1
2
3
# a={'fang','jie','lei','dong','tao'}
# b=a.copy()    #拷贝
# print(b)

 4 difference :差集只设有一个集合的

1
2
3
4
5
6
7
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a - b)   #差集
 
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.difference(b))    #查看差集

 5 difference_update:找差集并创新

1
2
3
4
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.difference_update(b)
# print(a)   #查找差集并更新

 6 symmetric_difference :找对称差集

1
2
3
4
5
6
7
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a ^ b)   #对称差集
#
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.symmetric_difference(b))   #查看对称差集

 7 symmetric_difference_update:  着对称差集并改进

1
2
3
4
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.symmetric_difference_update(b)
# print(a)        #查找对称差集并更新

 8 discard :根据指标删除

1
2
3
4
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.discard('jie')
# print(a)      #删除

 9 intersection:交集

1
2
3
4
5
6
7
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a & b)   #交集
 
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.intersection(b))   #交集

 10 intersection_update:交集并立异

1
2
3
4
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.intersection_update(b)
# print(a)      #查找并集并更新

 11 union  :并集

1
2
3
4
5
6
7
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a | b)    #并集
#
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.union(b))            #并集

 12 isdisjoint :剖断是不是无交集

1
2
3
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# print(a.isdisjoint(b))     #判断是否无交集

 13 iscubset :判别是还是不是是子集

1
2
3
# a={'fang','jie','lei','dong','tao'}
# b={'fang','jie'}
# print(b.issubset(a))   #判断b是不是a的子集

 14 issuperset :判别是或不是是父集

1
2
3
# a={'fang','jie','lei','dong','tao'}
# b={'fang','jie'}
# print(a.issuperset(b))    #判断a是不是b的父集

 15 pop 随机删除

1
2
3
# a={'fang','jie','lei','dong','tao'}
# a.pop()
# print(a)    #随机删除

 16 remove :钦点删除

1
2
3
# a={'fang','jie','lei','dong','tao'}
# a.remove('fang')
# print(a)      #指定元素删除

 17 update :更新

1
2
3
4
# a={'fang','jie','lei','dong','tao'}
# b={'fang','rei','cheng'}
# a.update()
# print(a)    #更新

 18 len :长度

1
2
# a={'fang','jie','lei','dong','tao'}
# print(len(a))

set一般的情况下,集结属性后面必需放群集,属性前边能够放大肆的数据类型,集结里面的值是不得以变得。{}私下认可是字典,想要创造会集就是set()

三 文件操作

 文件的常用方法右

  1,r(read):读取文件,只好读取,无法其余操作;
 r+:不光是足以读取,并且还能写入,r+是先读取再写入

  2 ,w(write):写入文件,只好写入;   
w+:不过能够写入,并且还是可以够写入过后再去读取。

  3 ,a(append):追加内容,只好扩展;  a+:追加过后还足以读取文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# #以bytes类型写入文件
# a=b'\xe4\xbd\xa0\xe4\xb8\xaa\xe5\xa4\xa7\xe5\x82\xbb\xe5\x8f\x89\r\n\xe9\x82\xa3\xe4\xba\xba\xe5\xb0\xb1\xe6\x98\xaf\xe4\xbd\xa0'
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','wb')
# b=f.write(a)
# f.close()
#
# #以w覆盖的方式写入
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w',encoding='utf-8')
# b=f.write('dsdf')
# f.close()
 
#
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd')
# f.seek(0)       #seek()指定光标的位置
# a=f.read()
# f.close()
# print(a)
 
 
 
# a#追加的方式添加
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','a',encoding='utf-8')
# b=f.write('dsdf')
# f.close()
 
##追加过后再读取
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','a+',encoding='utf-8')
# b=f.write('dsdf')
# f.seek(0)
# a=f.read()
# f.close()
# print(a)
 
 
# #以bytes类型读取
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='rb')
# a=f.read()
# f.close()
# print(a)
#
# #以utf-8格式读取
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r',encoding='utf-8')
# a=f.read()
# f.close()
# print(a)
 
##先读取在追加
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r+',encoding='utf-8')
# a=f.read()
# f.seek(3)
# f.write('jie')
# f.close()
# print(a)
#

 文件下的特性操作:

  1 read:读取文件

1
2
3
# with open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','r',encoding='utf-8')as f :
#     obj=f.read()
# print(obj)

  2 write:写入文件

1
2
3
#格式2 :
# with open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w',encoding='utf-8')as f :
#     f.write('yi')

  3 seek:调解光标的任务

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd')
# f.seek(0)       #seek()指定光标的位置
# a=f.read()
# f.close()
# print(a)

  4 tell:读取光标的地方

1
2
3
4
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# a=f.tell()   #查找光标的位置
# print(a)

  5 writable:是不是可写

1
2
3
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# a=f.writable()   #判断是否可写
# print(a)

  6 readable:是还是不是可读

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readable()   #判断是否可读
# f.close()
# print(a)

  7 close:关闭文件

1
2
3
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# f.close()      #关闭

  8 flush:刷到硬盘

1
2
3
4
5
6
7
# f=open('E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt',mode='r+',encoding='utf-8')
# a=f.read()
# f.seek(3)
# f.flush()      #flush 刷到硬盘
# f.write('jie')
# f.close()
# print(a)

  9 fileno:文件对象

1
2
3
4
5
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# a=f.fileno()             #文件对象
# f.close()    
# print(a)

  10 isatty :判定是或不是输出设备

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.isatty()      #判断是否是输出设备
# f.close()
# print(a)

  11 readline:读取一行内容

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readline()   #只读取整行
# f.close()
# print(a)

  12 seekable:判别是否可设置指针

1
2
3
4
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# a=f.seekable()    #判断是否可设置指针
# print(a)

  13 truncate : 光标前面的从头到尾的经过不要了,只要光标后面包车型客车从头到尾的经过

1
2
3
4
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs\ndas')
# f.truncate(5)       #指定光标的位置,然后再保留光标前面的内容是删除光标后面的内容
# f.close()

  14 readlines:读取全数的原委,然后一块监督指点内部存储器

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# a=f.readlines()      #全部读取,返回是列表,元素字符串
# f.close()
# print(a)

 python2 中的xreadlines就一定于python3中的for  line  in  f:

1
2
3
4
5
6
# f=open(r'E:\pycharm\pycharm\PyCharm Community Edition 2017.1.3\day7\jie.txt','w+',encoding='utf-8')
# f.write('dsdfdfsd\nfsd\nfgs')
# f.seek(0)
# for line in f:
#     print(line)
# f.close()
标签:,

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章

网站地图xml地图