본문 바로가기
C.W.K.
Stream
Lesson 02 of 08 · published

Key 와 값 — bare, quoted, dotted

~10 min · toml, keys, syntax

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

세 key 스타일, 값엔 한 규칙

Bare key

가장 기본이야. letters_and_underscores_only_123 처럼 쓰고, 쓸 수 있는 문자는 A-Z a-z 0-9 _ - 뿐이야. 스페이스도, 점도, 특수 문자도 못 써.

Quoted key

특수 문자나 스페이스가 들어가야 하면 큰따옴표나 작은따옴표로 감싸. "key with spaces" = "value" 이렇게. escape 규칙은 basic string 과 똑같아.

Dotted key

key 경로에 점을 찍으면 그게 곧 중첩이야. server.host = "localhost"[server] 아래 host = "localhost" 를 쓴 것과 같아. 점으로 나뉜 조각 하나하나가 bare 든 quoted 든 자기 규칙을 따르면 돼서, servers."my-host".port = 8000 같은 것도 잘 먹어.

이름 당 key 하나

TOML 은 같은 층에 같은 이름이 두 번 나오는 걸 거부해. name = "a"\nname = "b" 는 그대로 파스 에러야. JSON 은 이 경우를 아예 정의 안 해뒀고 YAML 은 보통 뒤엣것을 취하는데, TOML 은 일부러 막았어. 헷갈릴 여지가 없는 config 가 이 포맷이 내세우는 강점이거든.

'dotted key vs table' 미묘함: a.b = 1[a]
b = 1 은 파싱된 값은 같지만, 뒤에 나오는 [a] block 과 부딪힐 때 다르게 굴어. 요즘 TOML 은 둘을 섞어 쓰는 걸 허용하는데, a.b = 1 을 써놓고 나중에 [a] 를 다시 열면 'cannot redefine table' 에러가 나. 논리적인 섹션 하나당 한 스타일만 골라 써.

Code

세 key 스타일·toml
# Bare key
title = "My App"

# 하이픈 + 밑줄 + 숫자 든 bare key
api-token = ""
release_2026_q2 = true

# Quoted key — 스페이스나 특수 문자에 필요
"display name" = "Pippa"
"key.with.dots" = "escaped — single literal key, not a path"

# Dotted key — [server] + host = "localhost" 와 등가
server.host = "localhost"
server.port = 8000
같은 데이터, 두 스타일·toml
# 스타일 A — dotted key
database.host = "localhost"
database.port = 5432
database.user = "postgres"

# 스타일 B — table
[database]
host = "localhost"
port = 5432
user = "postgres"
중복 key — 파스 에러·toml
# 'duplicate key: name' 으로 죽음
name = "first"
name = "second"

# 이것도 죽음 — 다른 문법, 같은 논리 key
[server]
name = "first"
server.name = "second"   # 위 [server] 안의 name 과 같은 자리

External links

Exercise

실제 pyproject.toml 열어. [tool.ruff] 섹션 (또는 [tool.poetry.dependencies]) 찾아. 두 번 다시 작성: 한 번은 전부 dotted key 로 (tool.ruff.line-length = 100), 한 번은 전부 중첩 table 로. 그 섹션에 어느 형태가 더 자연스럽게 읽히는지 결정. 정답이 크기에 의존 — 그게 lesson.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.