편집 기록

편집 기록
  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.02.21

    파이썬 내용 수정 질문드려용!(질문 내용 수정)


    사용자가 텍스트 파일에 내용을 입력하고 그 내용을 수정하는 코드를 작성하고 있습니다.

    입력

    command = int(input("(1. input 2. edit) >> "))
    if command == 1:
        pattern_input = str(input("pattern >> ")).lower()
        template_input = str(input("template >> ")).lower()
    
        pattern = "<pattern>" + pattern_input + "</pattern>"
    
        content = ""
    
        if ";" in template_input:
            template_list = template_input.split("; ")
    
            for i in template_list:
                content += "<li>" + i + "</li>" + "\n"
    
            template = "<template>" + "<random>" + "\n" + content + "</random>" + "</template>"
    
        else:
            content = template_input
            template = "<template>" + content + "</template>"
    
        category = "<category>" + pattern + "\n" + template + "</category>"
        with open('file.txt', 'a+t') as f:
            f.write(category + "\n")
        print(category)
    

    수정

    • 파이썬에서 텍스트 파일을 불러옴
    • 해당 파일에서 특정 문장(사용자 입력1)이 있는지 확인
    • 해당 문장을 바꿀 문장(사용자 입력2) 문장으로 바꾸기

    이렇게 진행을 하려고 하는데 파일을 읽어올 때

    1. read나 readlines중에 어떤걸 사용해야 할까요?
    2. 파일 입출력시 read와 write가 동시에 가능한지 ?
    3. 특정 문장을 찾기 위해서는if "*" in file: 구문을 사용하면 될까요?
    4. 문장을 바꾸기 위해서 replace 함수를 쓰면 될까요?

    도와주시면 감사하겠습니다.

  • 프로필 nowp님의 편집
    날짜2020.02.21

    파이썬 내용 수정 질문드려용!


    사용자가 텍스트 파일에 내용을 입력하고 그 내용을 수정하는 코드를 작성하고 있습니다.

    1. 입력
    command = int(input("(1. input 2. edit) >> "))
    
    def userInput():
        pass
    
    if command == 1:
        pattern_input = str(input("pattern >> ")).lower()
        template_input = str(input("template >> ")).lower()
    
        pattern = "<pattern>" + pattern_input + "</pattern>"
    
        content = ""
    
        if ";" in template_input:
            template_list = template_input.split("; ")
    
            for i in template_list:
                content += "<li>" + i + "</li>" + "\n"
    
            template = "<template>" + "<random>" + "\n" + content + "</random>" + "</template>"
    
        else:
            content = template_input
            template = "<template>" + content + "</template>"
    
        category = "<category>" + pattern + "\n" + template + "</category>"
        with open('file.txt', 'a+t') as f:
            f.write(category + "\n")
        print(category)
    
    1. 수정
      • 파이썬에서 텍스트 파일을 불러옴
      • 해당 파일에서 특정 문장(사용자 입력1)이 있는지 확인
      • 해당 문장을 바꿀 문장(사용자 입력2) 문장으로 바꾸기

    이렇게 진행을 하려고 하는데 파일을 읽어올 때

    1. read나 readlines중에 어떤걸 사용해야 할까요?
    2. 특정 문장을 찾기 위해서는if "*" in file: 구문을 사용하면 될까요?
    3. 문장을 바꾸기 위해서 replace 함수를 쓰면 될까요?

    도와주시면 감사하겠습니다.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.02.21

    파이썬 내용 수정 질문드려용!


    사용자가 텍스트 파일에 내용을 입력하고 그 내용을 수정하는 코드를 작성하고 있습니다.

    1. 입력 ``` command = int(input("(1. input 2. edit) >> "))

    def userInput(): pass

    
    

    if command == 1: pattern_input = str(input("pattern >> ")).lower() template_input = str(input("template >> ")).lower()

    pattern = "<pattern>" + pattern_input + "</pattern>"
    
    content = ""
    
    if ";" in template_input:
        template_list = template_input.split("; ")
    
        for i in template_list:
            content += "<li>" + i + "</li>" + "\n"
    
        template = "<template>" + "<random>" + "\n" + content + "</random>" + "</template>"
    
    else:
        content = template_input
        template = "<template>" + content + "</template>"
    
    category = "<category>" + pattern + "\n" + template + "</category>"
    with open('file.txt', 'a+t') as f:
        f.write(category + "\n")
    print(category)
    
    
    
    2. 수정
     -  파이썬에서 텍스트 파일을 불러옴
     - 해당 파일에서 특정 문장(사용자 입력1)이 있는지 확인
     - 해당 문장을 바꿀 문장(사용자 입력2) 문장으로 바꾸기
    
    이렇게 진행을 하려고 하는데 파일을 읽어올 때
     1.  read나 readlines중에 어떤걸 사용해야 할까요?
     2. 특정 문장을 찾기 위해서는 if "*" in file: 구문을 사용하면 될까요?
     3. 문장을 바꾸기 위해서 replace 함수를 쓰면 될까요?
    
    ㅠㅠ 도와주시면 감사하겠습니다.