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". basic string 과 같은 escape 규칙.

Dotted key

key 경로의 점이 중첩 만듦: server.host = "localhost"[server] + host = "localhost" 의 단축형. dotted 경로의 각 segment 가 bare/quoted 규칙 따름: servers."my-host".port = 8000 작동.

이름 당 key 하나

TOML 이 같은 단계의 중복 key 거부 — name = "a"\nname = "b" 가 파스 에러. (JSON 과 비교: undefined behavior. YAML: 보통 'last wins'.) 일부러; 모호함 없는 config 가 TOML 의 셀링 포인트.

'dotted key vs table' 미묘함: a.b = 1[a]
b = 1 가 같은 파싱 값 만들지만 나중 [a] block 과 다르게 상호작용. modern 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
name = "first"
[ ]                  # 명시적 root
name = "second"

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

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

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