Slide 1

Slide 1 text

Respect the Built-in Names Hayao Suzuki PyCon JP 2017 Lightning Talk at Waseda Univ. September 8, 2017

Slide 2

Slide 2 text

Who Am I? About Me Name Hayao Suzuki (@CardinalXaro) Blog http://xaro.hatenablog.jp/ Major Mathematics (Combinatorics, Number Theory) Work Python Programmer at iRidge, Inc. Reviewed Books Effective Python (O’Reilly Japan) ΞϧΰϦζϜΫΠοΫϦϑΝϨϯε ୈ 2 ൛ (O’Reilly Japan) ॳΊͯͷ PHP (O’Reilly Japan) Effective Debugging (O’Reilly Japan) ͢Β͢ΒΘ͔Δ Python ʢᠳӭࣾʣ Python ͱ JavaScript Ͱ͸͡ΊΔσʔλϏδϡΞϥΠθʔγϣϯ (O’Reilly Japan) 2 / 9

Slide 3

Slide 3 text

Today’s Theme Respect the Built-in Names 3 / 9

Slide 4

Slide 4 text

Examples sum is a name of built-in function but... sum = 0 for i in range(10): sum = sum + i print(sum) sum ΁ͷ୅ೖ͸ѱ͍จ໌ʂʂ 4 / 9

Slide 5

Slide 5 text

Examples id is a name of built-in function but... id = 12345 name = "Ξϧςϥ" print(f"Α͏ͦ͜{name}͞Μ (id={id})") id ΁ͷ୅ೖ͸ѱ͍จ໌ʂʂ 5 / 9

Slide 6

Slide 6 text

Examples list is a name of sequence class but... list = [1, 2, 3, 4, 5] for i in range(len(list)): print(list[i]) list ΁ͷ୅ೖ͸ѱ͍จ໌ʂʂ 6 / 9

Slide 7

Slide 7 text

Examples dict is a name of mapping class but... dict = {"spam": 0, "egg": 1, "bacon":2} for k, v in dict.items(): print("%s: %s" % (k, v)) dict ΁ͷ୅ೖ͸ѱ͍จ໌ʂʂ 7 / 9

Slide 8

Slide 8 text

Examples json is a name of built-in module but... import json import requests response = requests.get("https://examples.com") if response.status_code == 200: json = response.json() print(json.keys()) json ΁ͷ୅ೖ͸ѱ͍จ໌ʂʂ 8 / 9

Slide 9

Slide 9 text

Conclusion Respect the built-in names Abuse of names causes a trouble. If you provide objects with the same name as a built-in value, read builtins module’s documents. 9 / 9