1 ๋ถ„ ์†Œ์š”

Python ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€ ์ฝ๊ธฐ

๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด ํ•ญ์ƒ ์˜ค๋ฅ˜ ์ƒํ™ฉ์— ๋ถ€๋”ชํžŒ๋‹ค.

ํŒŒ์ด์ฌ์€ ๊ทธ๋Ÿฐ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋ณดํ†ต Traceback ์ด๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค.

์ด๋Ÿฐ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ๋Š” ๋ฐฉ๋ฒ•์„ ์ ์–ด๋ณธ๋‹ค.

Traceback

Traceback ์ด๋ž€, ํŒŒ์ด์ฌ์—์„œ ํŠน์ • ์ง€์ ์—์„œ ํ•จ์ˆ˜ ํ˜ธ์ถœ์— ๊ด€ํ•œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ๋‹ค ์ •๋„๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด, Traceback์˜ ํ˜„์žฌ ์ƒํƒœ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ , ์˜ค๋ฅ˜๋ฅผ ์ฝ˜์†”์— ๋„์šด๋‹ค.

def hello(name, msg):
		print(name, ":", meg)
	
hello("Junho", "Hello")

์˜ˆ๋ฅผ ๋“ค์–ด ์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์ž.

์œ„์˜ ์ฝ”๋“œ์—์„œ msg๋Œ€์‹  meg ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌํ•œ๋‹ค.

meg๋Š” ํ•จ์ˆ˜ ์•ˆ์— ์ •์˜๊ฐ€ ๋œ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์•„๋‹ˆ๋‹ˆ, ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

์˜ค๋ฅ˜ ์ฝ”๋“œ๋Š” ์•„๋งˆ๋„ ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚˜์˜ฌ ๊ฒƒ์ด๋‹ค.

Traceback (most recent call last):
  File "error.py", line 4, in <module>
    hello("Junho", "Hello")
  File "error.py", line 2, in hello
    print(name, ":", meg)
NameError: name 'meg' is not defined. Did you mean: 'msg'?

Traceback์„ ์ฝ๋Š” ๋ฐฉ๋ฒ•?

Traceback ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ์„ ๋•Œ๋Š” ๋ฐ‘์—์„œ๋ถ€ํ„ฐ!! ์ฝ์œผ๋ฉด ๋œ๋‹ค.

NameError: name 'meg' is not defined. Did you mean: 'msg'?

๋จผ์ €, ๊ฐ€์žฅ ์•„๋ž˜ ๋ฌธ๊ตฌ์ธ NameError ๋ฅผ ์ฝ์œผ๋ฉด ๋œ๋‹ค.

โ€œmeg ๋ผ๋Š” ์ด๋ฆ„์˜ ๋ณ€์ˆ˜๊ฐ€ ์ •์˜๋˜์ง€ ์•Š์•˜๋‹ค. msg ๋กœ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ•œ๊ฑฐ์•ผ?โ€

์ด ๋ฌธ๊ตฌ๋ฅผ ๋ณด๋ฉด, NameError ๋ผ๋Š” ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๊ณ , ์ •์˜๋˜์ง€ ์•Š์€ ๋ณ€์ˆ˜ ์‚ฌ์šฉ์ด๋ผ๋Š” ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ๋‹ด๊ณ ์žˆ๋‹ค.

์ด์ฒ˜๋Ÿผ Traceback์˜ ๊ฐ€์žฅ ์•„๋ž˜ ๋ฌธ๊ตฌ๋Š” ์˜ˆ์™ธ์ฒ˜๋ฆฌ์™€ ์™œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋Š”์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ๋‹ค.

๋‹ค์Œ์œผ๋กœ ๊ทธ ์œ„์˜ ๋ฌธ๊ตฌ๋ฅผ ๋ณด๋ฉด,

File "error.py", line 2, in hello
    print(name, ":", meg)

์ด์ฒ˜๋Ÿผ ํ•จ์ˆ˜ ํ˜ธ์ถœ ์— ๊ด€ํ•œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ ์žˆ๋‹ค.

์œ„๋กœ ์˜ฌ๋ผ๊ฐˆ ์ˆ˜๋ก ๋” ์ƒ์œ„ ํ•จ์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋ฉฐ, ํ˜„์žฌ๋Š” ๋งจ ๋ฐ‘์ค„์ด๊ธฐ ๋•Œ๋ฌธ์— ์˜ค๋ฅ˜๊ฐ€๋ฐœ์ƒํ•œ ๋ถ€๋ถ„์— ๊ด€ํ•œ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ in hello ์˜ ๋ถ€๋ถ„์—์„œ hello ๋Œ€์‹  <module> ์ด๋ผ๋ฉด ์ตœ์ƒ์œ„ ์ฝ”๋“œ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

์ฐธ๊ณ  ์ž๋ฃŒ

[Python] ํŒŒ์ด์ฌ์˜ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ๋Š” ๋งค์šฐ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•

ํƒœ๊ทธ: , ,

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ