콘솔워크

특정 문자열을 메모장.txt 파일로 저장 본문

카테고리 없음

특정 문자열을 메모장.txt 파일로 저장

이휘재123 2023. 3. 9. 18:40
반응형
    # 메모장 저장
    def sentence_to_txt(self, file_name: str, sentence: str):
        save_path = os.path.join("경로를 입력해주세요", "폴더 이름")

		# 폴더가 없을 시 생성
        if os.path.isdir(save_path) == False:
            os.mkdir(save_path)
        else:
            pass

		# 위에서 선언한 경로에 메모장 파일을 생성함
        sentence_txt = os.path.join(save_path, f"{file_name}.txt")

        with open(sentence_txt, "w", encoding="UTF8") as f:
            f.write(sentence)
반응형