Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyerror in string format #83421

Closed
gerryc89 mannequin opened this issue Jan 7, 2020 · 3 comments
Closed

keyerror in string format #83421

gerryc89 mannequin opened this issue Jan 7, 2020 · 3 comments
Labels
3.8 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@gerryc89
Copy link
Mannequin

gerryc89 mannequin commented Jan 7, 2020

BPO 39240
Nosy @rhettinger, @ericvsmith, @ezio-melotti
Files
  • test.py: arranged test for recreate the problem, and a workaround
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-01-07.01:16:21.822>
    created_at = <Date 2020-01-07.01:01:11.775>
    labels = ['invalid', 'type-bug', '3.8']
    title = 'keyerror in string format'
    updated_at = <Date 2020-01-07.01:19:28.509>
    user = 'https://bugs.python.org/gerryc89'

    bugs.python.org fields:

    activity = <Date 2020-01-07.01:19:28.509>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-07.01:16:21.822>
    closer = 'eric.smith'
    components = []
    creation = <Date 2020-01-07.01:01:11.775>
    creator = 'gerryc89'
    dependencies = []
    files = ['48830']
    hgrepos = []
    issue_num = 39240
    keywords = []
    message_count = 3.0
    messages = ['359483', '359484', '359485']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'eric.smith', 'ezio.melotti', 'mrabarnett', 'gerryc89']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39240'
    versions = ['Python 3.8']

    @gerryc89
    Copy link
    Mannequin Author

    gerryc89 mannequin commented Jan 7, 2020

    Hi, i think tha this is a problem, i'm not have mutch experiencing in programming with python. I have added in the file the line that create the problem and a line that make fully functional. Thanks for the time.
    Gerry

    @gerryc89 gerryc89 mannequin added build The build process and cross-build topic-regex 3.8 only security fixes labels Jan 7, 2020
    @ericvsmith
    Copy link
    Member

    When creating a bug report, please show the actual errors that you get.

    This is not a bug in python. In line 5 you're looking for composer2['third'], so of course you'd need to define it.

    @ericvsmith ericvsmith added invalid type-bug An unexpected behavior, bug, or error and removed build The build process and cross-build topic-regex labels Jan 7, 2020
    @ericvsmith ericvsmith added invalid type-bug An unexpected behavior, bug, or error and removed build The build process and cross-build labels Jan 7, 2020
    @rhettinger
    Copy link
    Contributor

    Instead of doing lookups with square brackets, consider using the dict.get() method that returns a default value rather than raising a KeyError for a missing key.

    composer2[input1]  --> composer2.get(input1, 0)
    

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants