HayaoSuzuki
September 08, 2017
4k

# Respect the Built-in Names

PyCon JP 2017 Day1 Lightning Talk

## HayaoSuzuki

September 08, 2017

## Transcript

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

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

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

4. 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

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

6. 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

7. 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

8. 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

9. Conclusion
Respect the built-in names
Abuse of names causes a trouble.
If you provide objects with the same name as a built-in