$30 off During Our Annual Pro Sale. View Details »

Respect the Built-in Names

HayaoSuzuki
September 08, 2017

Respect the Built-in Names

PyCon JP 2017 Day1 Lightning Talk

HayaoSuzuki

September 08, 2017
Tweet

More Decks by HayaoSuzuki

Other Decks in Technology

Transcript

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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide