018_IO

Posted liujun5319

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了018_IO相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# Author:liujun

f = open("test","r",encoding="utf-8")
# r --> readable
# r --> writeable
# r+ --> read and write
# w+ --> write and read

#print(f.read())

#for i in range(5):
# print(f.readline())

#for line in f.readlines():
# print(line.strip())

#for index,line in enumerate(f.readlines()):
# print(index,line.strip())

#for line in f: # This kind of traverse is recommanded
# print(line.strip())

print(f.tell())
print(f.readline())
print(f.tell())
# Used to get the location of file pointer.
f.seek(10)
# Used to set the location of file pointer
print(f.read(50))
print(f.readline())
print(f.fileno())
f.flush()
# Forces the contents of the cache to be written to disk.









How to modify a file
#!/usr/bin/env python
# Author:liujun

f = open("test", "r", encoding="utf-8")
f_new = open("test.bak","w",encoding="utf-8")

for line in f:
if "iphone" in line:
line = line.replace("iphone","iphoneX");
f_new.write(line)
f.close()
f_new.close()














































































以上是关于018_IO的主要内容,如果未能解决你的问题,请参考以下文章

018_异步_Schedule

_018_回收子进程_信号传参

Atcoder Grand Contest 018 E - Sightseeing Plan

018_jsdoc详解

018_四数之和

dljd_(018-020)_jdbc中mysql的事务管理