2011년 11월 7일 월요일

04 간단한 메모장 만들기

addline = input('wirte(if you exit, type x) : ')



def write() :

    fid = open('log1.txt', 'a')

    print(addline, file=fid)

    fid.close()

    fidr = open('log1.txt', 'r')

    line = fidr.readlines()

    print(line)

    fidr.close()

   

while addline != 'x' :   

    if addline != 'x' :

        write()

        addline = input('wirte(if you exit, type x) : ')



print('Good Job!')


>>>

wirte(if you exit, type x) : legitimate

['legitimate\n']

wirte(if you exit, type x) : 합법적인

['legitimate\n', '합법적인\n']

wirte(if you exit, type x) : x

Good Job!





  • 메모 후 파일을 닫을 때 자동으로 기록 날짜를 적으려면 다음과 같이 합니다.


import datetime



addline = input('wirte(if you exit, type x) : ')



def write() :

    fid = open('log1.txt', 'a')

    print(addline, file=fid)

    fid.close()

    fidr = open('log1.txt', 'r')

    line = fidr.readlines()

    print(line)

    fidr.close()



def x() :

    fid = open('log1.txt', 'a')

    when = datetime.datetime.now()

    print(when, file=fid)

    print('Good Job!!')

    fid.close()

   

while addline != 'x' :   

    if addline != 'x' :

        write()

        addline = input('wirte(if you exit, type x) : ')



x()


>>>

wirte(if you exit, type x) : instance

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n']

wirte(if you exit, type x) : 실례

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n']

wirte(if you exit, type x) : such an instance to exist

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n', 'such an instance to exist\n']

wirte(if you exit, type x) : x

Good Job!!

>>>

wirte(if you exit, type x) : imbue

['legitimate\n', '합법적인\n', 'ostentatious\n', '자랑삼아 드러내는\n', 'there is abundance of ostentatious cerenonies\n', 'instance\n', '실례\n', 'such an instance to exist\n', '2011-11-07 16:34:48.721262\n', 'imbue\n']

wirte(if you exit, type x) :


이 글은 스프링노트에서 작성되었습니다.

댓글 없음:

댓글 쓰기