Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Respect the Built-in Names

0350fb935be160186cd72472c9e5543b?s=47 HayaoSuzuki
September 08, 2017

Respect the Built-in Names

PyCon JP 2017 Day1 Lightning Talk

0350fb935be160186cd72472c9e5543b?s=128

HayaoSuzuki

September 08, 2017
Tweet

Transcript

  1. Respect the Built-in Names Hayao Suzuki PyCon JP 2017 Lightning

    Talk at Waseda Univ. September 8, 2017
  2. 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
  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 value, read builtins module’s documents. 9 / 9