본문 바로가기
Python/Python

csv생성과 os를 통한 파일경로 생성

by Sondho 2020. 7. 20.
import os
import csv


# 파일 경로 생성.
try:
    if not (os.path.isdir("csv_files")):
        os.makedirs(os.path.join("csv_files"))
except OSError as e:
    if e.errno != errno.EEXIST:
        print("Failed to create directory!")
        raise

# scv파일 생성 및 쓰기
f = open(f"csv_files/practice.csv", "w", encoding="utf-8")
wr = csv.writer(f)
wr.writerow(["place", "title", "time", "pay", "date"])
f.close

'Python > Python' 카테고리의 다른 글

재귀함수와 return  (2) 2020.07.17
if문 - 다양한 조건부 표현식  (0) 2020.07.17
lambda, sorted()  (0) 2020.05.13
문자열 뒤집기 - 문자열 슬라이싱  (0) 2020.05.08
int형 list를 .join으로 꺼내기  (0) 2020.05.05

댓글