[Python] 파일 입출력

f=open(“C:\Windows\System32\drivers\etc\hosts”) #파일 객체 생성

f2=open(“out.log”,”w”)

line=f.readline() #파일 read

while line:

    print line,    # ,는 줄바꿈 생략

    #print(line,end=”) #파이썬3

    print >>f2,line # f2에 line 내용 출력

    #print(line,file=f2)  #파이썬3

    line=f.readline()

f.close()

for line2 in open(“C:\Windows\System32\drivers\etc\hosts_tmp”):

    print line2,


댓글 남기기

바로가기