.csv 포맷을 .md 파일로 생성하기Generating a CSV format as a .md file
@ O612
파이썬을 이용해서 .csv를 .md로 변환합니다.
Convert .csv to .md using Python.
- 언어
- Python
- 타입스크립트 사용 여부
- 사용 안함
컴포넌트Component
국문Korean
# csv2md_컨버팅.py
import csv
import os
csv_파일_경로 = 'CSV파일.csv'
출력_폴더 = '마크다운'
os.makedirs(출력_폴더, exist_ok=True)
with open(csv_파일_경로, mode='r', encoding='utf-8-sig') as 파일:
읽기 = csv.DictReader(파일)
for 행 in 읽기:
번호 = 행['idx']
제목 = 행['subject']
설명 = 행['description']
md_파일_경로 = os.path.join(출력_폴더, f'{번호}.md')
with open(md_파일_경로, mode='w', encoding='utf-8-sig') as md_파일:
md_파일.write(f'# {제목}\n\n{설명}\n')
print("마크다운 파일 생성 완료")
영문English
# csv2md.py
import csv
import os
csv_file_path = 'csvFile.csv'
output_folder = 'markdowns'
os.makedirs(output_folder, exist_ok=True)
with open(csv_file_path, mode='r', encoding='utf-8-sig') as file:
reader = csv.DictReader(file)
for row in reader:
idx = row['idx']
subject = row['subject']
description = row['description']
md_file_path = os.path.join(output_folder, f'{idx}.md')
with open(md_file_path, mode='w', encoding='utf-8-sig') as md_file:
md_file.write(f'# {subject}\n\n{description}\n')
print("마크다운 파일 생성 완료")
사용방법How to use
국문Korean
# CSV파일.csv
# python 코드에서 지정한 파일명과 동일해야 함
idx,subject,description
2023061201,'가취가욥' 귀여워,언젯적 '가취가욥'인가
영문English
# csvFile.csv
# Must be the same as the filename specified in the python code
idx,subject,description
2023061201,'gachgayop' is so cute,Crossing the line?