티스토리 뷰




Read File




#r,w,rb,wb

f=open(filename,'r')


#read all String

file=f.read()


#read line

line=f.readline()


#print 5 line

for i in range(5):

print line


#get line example

with open('somefile') as openfileobject:
    for line in openfileobject:
        do_something()





Modify File

file_data=[]


with open(file_name,'r+') as file:


del file_data[:]

for line in file:

file_data.append(line.replace("aaaa","bbbb"))

file.seek(0)

file.writelines(file_data)










'Programming > Python' 카테고리의 다른 글

python if 문  (0) 2017.04.27
python Class  (0) 2017.04.21
python string  (0) 2017.04.09
powershell tutorial ExecutePolicy  (0) 2017.03.20
pwntool gdb 연동  (0) 2017.02.14
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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
글 보관함