python 3 - 파일 수정 - 셸 의 sed 와 유사 한 기능 구현

# Auther: Aaron Fan

'''

r, ( )。
w, 。【 ; ; ; , 】
a, 。【 ;   ; ;】
f.close()
python 。 , str()
#r ( )
f = open('yesterday',encoding='utf-8')
data = f.read()
f.close()
print(data)
# 5
f = open('yesterday','r',encoding='utf-8')
for i in range(5):
   print(f.readline())
#
f = open('yesterday','r',encoding='utf-8')
for line in f.readlines():
   print(line)
# 3 , ( , , )
f = open('yesterday','r',encoding='utf-8')
for index,line in enumerate(f.readlines()):
   if index == 2:
       print('----- ----',line)
       continue
   print(line)
# , , ,
f = open('yesterday','r',encoding='utf-8')
for line in f:
   print(line)
#3
f = open('yesterday','r',encoding='utf-8')
count = 0
for line in f:
   if count == 2:
       print('------ ----',line)
   count += 1
   print(line)

#w ( , , )
f = open('yesterday','w',encoding='utf-8')
f.write("
")
f.write(" 2
")
f.write(" 3")

#a ( , , )
f = open('yesterday','a',encoding='utf-8')
f.write("test1
")

#
f = open('yesterday','r',encoding='utf-8')
#
print(f.tell())
print(f.readline())
print(f.tell())
# ( , )
f.seek(0)

#
print(f.encoding)
# ( , )
print(f.fileno())
#
print(f.isatty())
# ( )
f.flush()
# , , 0
#f.truncate()

#r+ ( , )
f = open('yesterday','r+',encoding='utf-8')
data = f.read()
print(data)
f.write("test...
")

# w+ a+ , ,
#rb
#wb
'''

'''
#with ( , ~, 《Python 》 )
# , , :
with open('log','r') as f:

   ...
#with , 。
# Python 2.7 with , :
with open('log1') as obj1, open('log2') as obj2:
   pass
'''

좋은 웹페이지 즐겨찾기