Python KeyError: руководство для начинающих

–û—à–∏–±–∫–∞ Python KeyError –≤–æ–∑–Ω–∏–∫–∞–µ—Ç –ø—Ä–∏ –ø–æ–ø—ã—Ç–∫–µ –¥–æ—Å—Ç—É–ø–∞ –∫ –Ω–µ—Å—É—â–µ—Å—Ç–≤—É—é—â–µ–º—É —ç–ª–µ–º–µ–Ω—Ç—É –≤ —Å–ª–æ–≤–∞—Ä–µ. –í—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø—Ä–∞–≤–∏—Ç—å —ç—Ç—É –æ—à–∏–±–∫—É, –∏–∑–º–µ–Ω–∏–≤ —Å–≤–æ—é –ø—Ä–æ–≥—Ä–∞–º–º—É, —á—Ç–æ–±—ã –≤—ã–±—Ä–∞—Ç—å —ç–ª–µ–º–µ–Ω—Ç –∏–∑ —Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ —Å–ª–æ–≤–∞—Ä—è. –ò–ª–∏ –≤—ã –º–æ–∂–µ—Ç–µ —Å–ø—Ä–∞–≤–∏—Ç—å—Å—è —Å —ç—Ç–æ–π –æ—à–∏–±–∫–æ–π, —Å–Ω–∞—á–∞–ª–∞ –ø—Ä–æ–≤–µ—Ä–∏–≤, —Å—É—â–µ—Å—Ç–≤—É–µ—Ç –ª–∏ –∫–ª—é—á.

–í—ã —Ç–æ–ª—å–∫–æ —á—Ç–æ –ø–æ–ª—É—á–∏–ª–∏ —Å–æ–æ–±—â–µ–Ω–∏–µ –æ–± –æ—à–∏–±–∫–µ KeyError? –ù–µ –≤–æ–ª–Ω—É–π—Ç–µ—Å—å! –ö–æ–≥–¥–∞ –≤–æ–∑–Ω–∏–∫–∞–µ—Ç KeyError, —ç—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –≤—ã –ø—ã—Ç–∞–µ—Ç–µ—Å—å –ø–æ–ª—É—á–∏—Ç—å –¥–æ—Å—Ç—É–ø –∫ –∫–ª—é—á—É –≤–Ω—É—Ç—Ä–∏ –Ω–µ—Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ —Å–ª–æ–≤–∞—Ä—è. –û–±—Ä–∞–±–æ—Ç–∞—Ç—å –∏ –∏—Å–ø—Ä–∞–≤–∏—Ç—å —ç—Ç—É –æ—à–∏–±–∫—É –ª–µ–≥–∫–æ, –µ—Å–ª–∏ –≤—ã –∑–Ω–∞–µ—Ç–µ, –∫–∞–∫ —ç—Ç–æ —Å–¥–µ–ª–∞—Ç—å.

KeyErrors –º–æ–∂–Ω–æ –æ–±—Ä–∞–±–æ—Ç–∞—Ç—å —Å –ø–æ–º–æ—â—å—é –±–ª–æ–∫–∞ try & hellip; except, –∏—Å–ø–æ–ª—å–∑—É—è " in " –∫–ª—é—á–µ–≤–æ–µ —Å–ª–æ–≤–æ –∏–ª–∏ –∑–∞—Ä–∞–Ω–µ–µ –ø—Ä–æ–≤–µ—Ä–∏–≤ –∫–ª—é—á —Å –ø–æ–º–æ—â—å—é –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏.

–í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –º—ã –ø–æ–≥–æ–≤–æ—Ä–∏–º –æ —Ç–æ–º, —á—Ç–æ —Ç–∞–∫–æ–µ Python KeyErrors –∏ –ø–æ—á–µ–º—É –æ–Ω–∏ –≤–æ–∑–Ω–∏–∫–∞—é—Ç. –ú—ã —Ä–∞—Å—Å–º–æ—Ç—Ä–∏–º –ø—Ä–∏–º–µ—Ä –æ—à–∏–±–∫–∏ –∏ —Å–ø–æ—Å–æ–±—ã –µ–µ –∏—Å–ø—Ä–∞–≤–ª–µ–Ω–∏—è, —á—Ç–æ–±—ã –≤—ã –∑–Ω–∞–ª–∏, –∫–∞–∫ —É—Å—Ç—Ä–∞–Ω—è—Ç—å –æ—à–∏–±–∫–∏ KeyErrors –≤ –±—É–¥—É—â–µ–º.

–î–∞–≤–∞–π—Ç–µ –ø—Ä–∏—Å—Ç—É–ø–∏–º!

–ß—Ç–æ —Ç–∞–∫–æ–µ –û—à–∏–±–∫–∞ Python KeyError?

–û—à–∏–±–∫–∞ Python KeyError –≤–æ–∑–Ω–∏–∫–∞–µ—Ç, –∫–æ–≥–¥–∞ –≤—ã –ø—ã—Ç–∞–µ—Ç–µ—Å—å –ø–æ–ª—É—á–∏—Ç—å –¥–æ—Å—Ç—É–ø –∫ —ç–ª–µ–º–µ–Ω—Ç—É –≤ —Å–ª–æ–≤–∞—Ä–µ, –∫–æ—Ç–æ—Ä—ã–π –Ω–µ —Å—É—â–µ—Å—Ç–≤—É–µ—Ç, —Å –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏–µ–º —Å–∏–Ω—Ç–∞–∫—Å–∏—Å–∞ –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏. –≠—Ç–∞ –æ—à–∏–±–∫–∞ –≤–æ–∑–Ω–∏–∫–∞–µ—Ç –∏–∑-–∑–∞ —Ç–æ–≥–æ, —á—Ç–æ Python –Ω–µ –º–æ–∂–µ—Ç –≤–µ—Ä–Ω—É—Ç—å –∑–Ω–∞—á–µ–Ω–∏–µ –¥–ª—è —ç–ª–µ–º–µ–Ω—Ç–∞, –∫–æ—Ç–æ—Ä–æ–≥–æ –Ω–µ—Ç –≤ —Å–ª–æ–≤–∞—Ä–µ.

–°–ª–æ–≤–∞—Ä—å Python - —ç—Ç–æ –Ω–∞–±–æ—Ä –ø–∞—Ä –∫–ª—é—á-–∑–Ω–∞—á–µ–Ω–∏–µ, –∫–æ—Ç–æ—Ä—ã–µ —Ö—Ä–∞–Ω—è—Ç—Å—è –≤ —Ñ–∏–≥—É—Ä–Ω—ã—Ö —Å–∫–æ–±–∫–∞—Ö ({}):

–ö–ª—é—á–∏: " name ", " price " –∏ " RAM " . –ö–ª—é—á–∏ –≤ —Å–ª–æ–≤–∞—Ä–µ –ø–æ—è–≤–ª—è—é—Ç—Å—è –ø–µ—Ä–µ–¥ –¥–≤–æ–µ—Ç–æ—á–∏–µ–º.

81% —É—á–∞—Å—Ç–Ω–∏–∫–æ–≤ –∑–∞—è–≤–∏–ª–∏, —á—Ç–æ –æ–Ω–∏ –ø–æ—á—É–≤—Å—Ç–≤–æ–≤–∞–ª–∏ —Å–µ–±—è –±–æ–ª–µ–µ —É–≤–µ—Ä–µ–Ω–Ω–æ –≤ —Å–≤–æ–∏—Ö –ø–µ—Ä—Å–ø–µ–∫—Ç–∏–≤–∞—Ö —Ä–∞–±–æ—Ç—ã –≤ —Å—Ñ–µ—Ä–µ –≤—ã—Å–æ–∫–∏—Ö —Ç–µ—Ö–Ω–æ–ª–æ–≥–∏–π –ø–æ—Å–ª–µ –ø–æ—Å–µ—â–µ–Ω–∏—è —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è. –ü–æ–ª—É—á–∏—Ç–µ –ø—Ä–∏–≥–ª–∞—à–µ–Ω–∏–µ –Ω–∞ —É—á–µ–±–Ω—ã–π –∫—É—Ä—Å —Å–µ–≥–æ–¥–Ω—è.

–°—Ä–µ–¥–Ω–∏–π –≤—ã–ø—É—Å–∫–Ω–∏–∫ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –ø–æ—Ç—Ä–∞—Ç–∏–ª –º–µ–Ω–µ–µ —à–µ—Å—Ç–∏ –º–µ—Å—è—Ü–µ–≤ –Ω–∞ —Å–º–µ–Ω—É –∫–∞—Ä—å–µ—Ä—ã, –æ—Ç –Ω–∞—á–∞–ª–∞ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –¥–æ –ø–æ–∏—Å–∫–∞ —Å–≤–æ–µ–π –ø–µ—Ä–≤–æ–π —Ä–∞–±–æ—Ç—ã.

–î–∞–≤–∞–π—Ç–µ –ø–æ—Å–º–æ—Ç—Ä–∏–º, —á—Ç–æ –ø—Ä–æ–∏–∑–æ–π–¥–µ—Ç. –µ—Å–ª–∏ –º—ã –ø–æ–ø—ã—Ç–∞–µ–º—Å—è –ø–æ–ª—É—á–∏—Ç—å –∫–æ–ª–∏—á–µ—Å—Ç–≤–æ USB-–ø–æ—Ä—Ç–æ–≤ –≤ –Ω–∞—à–µ–º —Å–ª–æ–≤–∞—Ä–µ:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç:

–≠—Ç–∞ –æ—à–∏–±–∫–∞ —Å–æ–æ–±—â–∞–µ—Ç –Ω–∞–º, —á—Ç–æ —É–∫–∞–∑–∞–Ω–Ω—ã–π –Ω–∞–º–∏ –∫–ª—é—á –Ω–µ —Å—É—â–µ—Å—Ç–≤—É–µ—Ç. –í —ç—Ç–æ–º —Å–ª—É—á–∞–µ –æ—Ç—Å—É—Ç—Å—Ç–≤—É–µ—Ç –∫–ª—é—á " usb_ports "

KeyError Python: —Ä–µ—à–µ–Ω–∏—è

–ß—Ç–æ–±—ã –æ–±—Ä–∞–±–æ—Ç–∞—Ç—å KeyError —Å–ª–æ–≤–∞—Ä—è Python, –≤—ã –º–æ–∂–µ—Ç–µ:

  • –ó–∞—Ä–∞–Ω–µ–µ –ø—Ä–æ–≤–µ—Ä—å—Ç–µ –∫–ª—é—á —Å –ø–æ–º–æ—â—å—é –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏.
  • –ò—Å–ø–æ–ª—å–∑—É–π—Ç–µ " in " –∫–ª—é—á–µ–≤–æ–µ —Å–ª–æ–≤–æ –¥–ª—è –ø—Ä–æ–≤–µ—Ä–∫–∏ –Ω–∞–ª–∏—á–∏—è –∫–ª—é—á–∞.
  • –ò—Å–ø–æ–ª—å–∑—É–π—Ç–µ –±–ª–æ–∫ try & hellip;

–ò—Å–ø–æ–ª—å–∑—É–π—Ç–µ –º–µ—Ç–æ–¥ —Å–ª–æ–≤–∞—Ä—è get ()

–º–µ—Ç–æ–¥ get () —Å–ª–æ–≤–∞—Ä—è Python –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –∑–Ω–∞—á–µ–Ω–∏–µ –≤ —Å–ª–æ–≤–∞—Ä–µ. –í—ã –º–æ–∂–µ—Ç–µ —É–∫–∞–∑–∞—Ç—å –∑–Ω–∞—á–µ–Ω–∏–µ –ø–æ —É–º–æ–ª—á–∞–Ω–∏—é —Å –ø–æ–º–æ—â—å—é –º–µ—Ç–æ–¥–∞ get (). –≠—Ç–æ –∑–Ω–∞—á–µ–Ω–∏–µ –ø–æ —É–º–æ–ª—á–∞–Ω–∏—é –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç—Å—è, –µ—Å–ª–∏ –∏–º—è —É–∫–∞–∑–∞–Ω–Ω–æ–≥–æ –≤–∞–º–∏ –∫–ª—é—á–∞ –Ω–µ –∏–º–µ–µ—Ç –∑–Ω–∞—á–µ–Ω–∏—è.

–£—á—Ç–∏—Ç–µ —Å–ª–µ–¥—É—é—â–∏–π –∫–æ–¥:

–î–∞–≤–∞–π—Ç–µ –∑–∞–ø—É—Å—Ç–∏–º –Ω–∞—à –∫–æ–¥ —Å –ø–æ–º–æ—â—å—é –∏–Ω—Ç–µ—Ä–ø—Ä–µ—Ç–∞—Ç–æ—Ä–∞ Python –∏ –ø–æ—Å–º–æ—Ç—Ä–∏–º, —á—Ç–æ –ø—Ä–æ–∏–∑–æ–π–¥–µ—Ç:

–ù–∞—à –∫–æ–¥ –∏—Å–ø–æ–ª—å–∑—É–µ—Ç –º–µ—Ç–æ–¥ —Å–ª–æ–≤–∞—Ä—è get () –¥–ª—è –ø–æ–ª—É—á–µ–Ω–∏—è " ALU " –∏–∑ –Ω–∞—à–µ–≥–æ —Å–ª–æ–≤–∞—Ä—å. –≠—Ç–æ–º—É –∏–º–µ–Ω–∏ –∫–ª—é—á–∞ –Ω–µ —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤—É–µ—Ç –Ω–∏ –æ–¥–Ω–æ –∑–Ω–∞—á–µ–Ω–∏–µ. –ú–µ—Ç–æ–¥ get () –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç —É–∫–∞–∑–∞–Ω–Ω–æ–µ –Ω–∞–º–∏ –∑–Ω–∞—á–µ–Ω–∏–µ –ø–æ —É–º–æ–ª—á–∞–Ω–∏—é, –∫–æ—Ç–æ—Ä–æ–µ —è–≤–ª—è–µ—Ç—Å—è " –Ω–µ–¥–æ—Å—Ç—É–ø–Ω–æ " .

–ü—Ä–µ–¥–≤–∞—Ä–∏—Ç–µ–ª—å–Ω–∞—è –ø—Ä–æ–≤–µ—Ä–∫–∞ –∫–ª—é—á–∞ —Å –ø–æ–º–æ—â—å—é –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏—è

–í—ã –º–æ–∂–µ—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏—Ç—å –Ω–∞–ª–∏—á–∏–µ –∫–ª—é—á–∞ —Å –ø–æ–º–æ—â—å—é –∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–∏—è, —á—Ç–æ–±—ã –∏–∑–±–µ–∂–∞—Ç—å –æ—à–∏–±–∫–∏ KeyError. –ï—Å–ª–∏ –∫–ª—é—á –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –≤ —Å–ª–æ–≤–∞—Ä–µ, –≤—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å —ç—Ç–æ—Ç –∫–ª—é—á. –í –ø—Ä–æ—Ç–∏–≤–Ω–æ–º —Å–ª—É—á–∞–µ –≤—ã –º–æ–∂–µ—Ç–µ —É–∫–∞–∑–∞—Ç—å —Å–≤–æ–µ–π –ø—Ä–æ–≥—Ä–∞–º–º–µ —Å–¥–µ–ª–∞—Ç—å —á—Ç–æ-—Ç–æ –µ—â–µ, –Ω–µ –∑–∞–≤–∏—Å—è—â–µ–µ –æ—Ç —ç—Ç–æ–≥–æ –∫–ª—é—á–∞.

–î–∞–≤–∞–π—Ç–µ –Ω–∞–ø–∏—à–µ–º –ø—Ä–æ–≥—Ä–∞–º–º—É, –∫–æ—Ç–æ—Ä–∞—è –ø–æ–ª—É—á–∞–µ—Ç –¥–æ—Å—Ç—É–ø –∫ –∫–ª—é—á–∞–º –≤ –Ω–∞—à–µ–º " raspberry_pi " —Å–ª–æ–≤–∞—Ä—å –Ω–∞ Python. –î–∞–≤–∞–π—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏–º, –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –ª–∏ –Ω–∞—à –∫–ª—é—á –≤ –Ω–∞—à–µ–º —Å–ª–æ–≤–∞—Ä–µ —Å –ø–æ–º–æ—â—å—é –∏–Ω–¥–µ–∫—Å–∞—Ü–∏–∏:

–ú—ã –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–ª–∏ Python " if " –æ–ø–µ—Ä–∞—Ç–æ—Ä , —á—Ç–æ–±—ã –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å—É—â–µ—Å—Ç–≤—É–µ—Ç –ª–∏ –Ω–∞—à –∫–ª—é—á. " raspberry_pi [get_key] " –≤–µ—Ä–Ω–µ—Ç –∑–Ω–∞—á–µ–Ω–∏–µ, —Ç–æ–ª—å–∫–æ –µ—Å–ª–∏ –∫–ª—é—á —Å—É—â–µ—Å—Ç–≤—É–µ—Ç. –≠—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –µ—Å–ª–∏ –Ω–∞—à –∫–ª—é—á —Å—É—â–µ—Å—Ç–≤—É–µ—Ç, –Ω–∞—à " if " –∑–∞—è–≤–ª–µ–Ω–∏–µ –±—É–¥–µ—Ç –≤—ã–ø–æ–ª–Ω–µ–Ω–æ. –ï—Å–ª–∏ –Ω–∞—à –∫–ª—é—á –Ω–µ —Å—É—â–µ—Å—Ç–≤—É–µ—Ç, " else " –∑–∞—è–≤–ª–µ–Ω–∏–µ –±—É–¥–µ—Ç –≤—ã–ø–æ–ª–Ω–µ–Ω–æ.

–î–∞–≤–∞–π—Ç–µ –ø–æ–ø—Ä–æ–±—É–µ–º –≤—ã—è—Å–Ω–∏—Ç—å –æ–±—ä–µ–º –æ–ø–µ—Ä–∞—Ç–∏–≤–Ω–æ–π –ø–∞–º—è—Ç–∏ –¥–ª—è –Ω–∞—à–µ–≥–æ Raspberry Pi:

–¢–µ–ø–µ—Ä—å –¥–∞–≤–∞–π—Ç–µ –ø–æ–ø—Ä–æ–±—É–µ–º –≤—ã—è—Å–Ω–∏—Ç—å, —Å–∫–æ–ª—å–∫–æ –ø–æ—Ä—Ç–æ–≤ USB –∏–º–µ–µ—Ç –∫–æ–º–ø—å—é—Ç–µ—Ä:

–ù–∞—à –∫–æ–¥ –Ω–µ –≤—ã–∑—ã–≤–∞–µ—Ç –æ—à–∏–±–∫—É KeyError! –≠—Ç–æ –ø–æ—Ç–æ–º—É, —á—Ç–æ –º—ã —Å–Ω–∞—á–∞–ª–∞ –ø—Ä–æ–≤–µ—Ä–∏–ª–∏, —Å—É—â–µ—Å—Ç–≤—É–µ—Ç –ª–∏ –Ω–∞—à –∫–ª—é—á, –ø—Ä–µ–∂–¥–µ —á–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –µ–≥–æ. –ï—Å–ª–∏ –±—ã –º—ã –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–ª–∏ raspberry_pi [get_key] –≤–Ω—É—Ç—Ä–∏ –Ω–∞—à–µ–≥–æ " else " , –Ω–∞—à –∫–æ–¥ –≤–µ—Ä–Ω–µ—Ç –æ—à–∏–±–∫—É KeyError.

–ò—Å–ø–æ–ª—å–∑—É—è –±–ª–æ–∫ try & hellip; except

Python try & hellip; except –±–ª–æ–∫ –ø–æ–ø—ã—Ç–∞–µ—Ç—Å—è –∑–∞–ø—É—Å—Ç–∏—Ç—å —Å—Ç—Ä–æ–∫—É –∫–æ–¥–∞. –ï—Å–ª–∏ —ç—Ç–∞ —Å—Ç—Ä–æ–∫–∞ –∫–æ–¥–∞ –Ω–µ –º–æ–∂–µ—Ç –±—ã—Ç—å –∑–∞–ø—É—â–µ–Ω–∞, –Ω–∞—à –∫–æ–¥ –≤—ã–∑–æ–≤–µ—Ç –Ω–∞—Å—Ç—Ä–∞–∏–≤–∞–µ–º—É—é –æ—à–∏–±–∫—É –≤ —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤–∏–∏ —Å —É–∫–∞–∑–∞–Ω–Ω—ã–º–∏ –≤–∞–º–∏ –∏—Å–∫–ª—é—á–µ–Ω–∏—è–º–∏.

–ú—ã –º–æ–∂–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –±–ª–æ–∫ try & hellip; except, —á—Ç–æ–±—ã –æ–ø—Ä–µ–¥–µ–ª–∏—Ç—å –Ω–∞–ª–∏—á–∏–µ –æ—à–∏–±–∫–∏ –∏ –æ—Å—Ç–∞–Ω–æ–≤–∏—Ç—å –Ω–µ–æ–∂–∏–¥–∞–Ω–Ω—É—é –æ—à–∏–±–∫—É KeyError, –∫–æ—Ç–æ—Ä–∞—è –Ω–µ –ø–æ–º–æ–∂–µ—Ç –Ω–∞—à–µ–π –ø—Ä–æ–≥—Ä–∞–º–º–µ Python.

–î–∞–≤–∞–π—Ç–µ –æ–ø—Ä–µ–¥–µ–ª–∏–º –Ω–∞—Å—Ç—Ä–∞–∏–≤–∞–µ–º—É—é –æ—à–∏–±–∫—É –¥–ª—è –Ω–∞—à–µ–≥–æ –∫–æ–º–ø—å—é—Ç–µ—Ä–Ω–æ–≥–æ –ø—Ä–∏–º–µ—Ä–∞ –∏–∑ –ø—Ä–µ–¥—ã–¥—É—â–µ–≥–æ, –∏—Å–ø–æ–ª—å–∑—É—è –±–ª–æ–∫ try & hellip; except:

"–ö–∞—Ä—å–µ—Ä–Ω–∞—è –∫–∞—Ä–º–∞ –≤–æ—à–ª–∞ –≤ –º–æ—é –∂–∏–∑–Ω—å –∫–æ–≥–¥–∞ —è –Ω—É–∂–¥–∞–ª—Å—è –≤ —ç—Ç–æ–º –±–æ–ª—å—à–µ –≤—Å–µ–≥–æ, –∏ –±—ã—Å—Ç—Ä–æ –ø–æ–º–æ–≥ –º–Ω–µ –ø–æ–¥–æ–±—Ä–∞—Ç—å –±—É—Ç–∫–µ–º–ø. –ß–µ—Ä–µ–∑ –¥–≤–∞ –º–µ—Å—è—Ü–∞ –ø–æ—Å–ª–µ –≤—ã–ø—É—Å–∫–∞ —è –Ω–∞—à–ª–∞ —Ä–∞–±–æ—Ç—É —Å–≤–æ–µ–π –º–µ—á—Ç—ã, –∫–æ—Ç–æ—Ä–∞—è —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤–æ–≤–∞–ª–∞ –º–æ–∏–º —Ü–µ–Ω–Ω–æ—Å—Ç—è–º –∏ —Ü–µ–ª—è–º –≤ –∂–∏–∑–Ω–∏! "

–í–µ–Ω–µ—Ä–∞, –∏–Ω–∂–µ–Ω–µ—Ä-–ø—Ä–æ–≥—Ä–∞–º–º–∏—Å—Ç –≤ Rockbot

< p> –ú—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –±–ª–æ–∫ try & hellip; except, —á—Ç–æ–±—ã –ø–æ–ø—ã—Ç–∞—Ç—å—Å—è –≤—ã–≤–µ—Å—Ç–∏ –Ω–∞ –∫–æ–Ω—Å–æ–ª—å –∫–æ–Ω–∫—Ä–µ—Ç–Ω—É—é –∏–Ω—Ñ–æ—Ä–º–∞—Ü–∏—é –æ –∫–æ–º–ø—å—é—Ç–µ—Ä–µ Raspberry Pi. –ï—Å–ª–∏ –Ω–∞—à –∫–æ–¥ –≤—ã–∑—ã–≤–∞–µ—Ç –æ—à–∏–±–∫—É KeyError –≥–¥–µ-–Ω–∏–±—É–¥—å –≤ –±–ª–æ–∫–µ " try ", –Ω–∞—à –∫–æ–¥ –≤—ã–ø–æ–ª–Ω—è–µ—Ç —Å–æ–¥–µ—Ä–∂–∏–º–æ–µ " except " block.

–≠—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –∫–∞–∂–¥—ã–π —Ä–∞–∑, –∫–æ–≥–¥–∞ –≤–æ–∑–Ω–∏–∫–∞–µ—Ç KeyError, –Ω–∞ –∫–æ–Ω—Å–æ–ª—å –ø–µ—á–∞—Ç–∞–µ—Ç—Å—è " –≠—Ç–∞ –∏–Ω—Ñ–æ—Ä–º–∞—Ü–∏—è –Ω–µ–¥–æ—Å—Ç—É–ø–Ω–∞ & rdquo ;. –î–∞–≤–∞–π—Ç–µ –ø–æ–ø—Ä–æ–±—É–µ–º —É–∑–Ω–∞—Ç—å –∏–º—è –∫–æ–º–ø—å—é—Ç–µ—Ä–∞ :

–¢–µ–ø–µ—Ä—å –¥–∞–≤–∞–π—Ç–µ –ø–æ–ø—Ä–æ–±—É–µ–º —É–∑–Ω–∞—Ç—å –æ –¥–æ—Å—Ç—É–ø–Ω–æ—Å—Ç–∏ USB-–ø–æ—Ä—Ç–∞ –∫–æ–º–ø—å—é—Ç–µ—Ä–∞:

–ù–∞—à –∫–æ–¥ –≤—ã–∑—ã–≤–∞–µ—Ç –æ—à–∏–±–∫—É KeyError –≤–Ω—É—Ç—Ä–∏ " try " –±–ª–æ–∫–∏—Ä–æ–≤–∞—Ç—å. –≠—Ç–æ –∑–∞—Å—Ç–∞–≤–ª—è–µ—Ç –Ω–∞—à –∫–æ–¥ –≤—ã–ø–æ–ª–Ω—è—Ç—å –∫–æ–º–∞–Ω–¥—É " except " –±–ª–æ–∫ –∫–æ–¥–∞.

–ü—Ä–µ–¥–≤–∞—Ä–∏—Ç–µ–ª—å–Ω–æ –ø—Ä–æ–≤–µ—Ä—å—Ç–µ –Ω–∞–ª–∏—á–∏–µ –∫–ª—é—á–∞

" in " –∫–ª—é—á–µ–≤–æ–µ —Å–ª–æ–≤–æ —è–≤–ª—è–µ—Ç—Å—è –æ–¥–Ω–∏–º –∏–∑ –æ–ø–µ—Ä–∞—Ç–æ—Ä–æ–≤ —á–ª–µ–Ω—Å—Ç–≤–∞ Python. –û–Ω –ø—Ä–æ–≤–µ—Ä—è–µ—Ç, –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –ª–∏ —ç–ª–µ–º–µ–Ω—Ç –≤ —Å–ø–∏—Å–∫–µ –∑–Ω–∞—á–µ–Ω–∏–π. –í—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å " in " –∫–ª—é—á–µ–≤–æ–µ —Å–ª–æ–≤–æ, —á—Ç–æ–±—ã –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –ª–∏ –∫–ª—é—á –≤ —Å–ª–æ–≤–∞—Ä–µ.

–≠—Ç–∞ –ø—Ä–æ–≥—Ä–∞–º–º–∞ –ø—Ä–æ–≤–µ—Ä—è–µ—Ç, —Å—É—â–µ—Å—Ç–≤—É–µ—Ç –ª–∏ –∫–ª—é—á –ø–µ—Ä–µ–¥ –≤—ã–≤–æ–¥–æ–º –µ–≥–æ –∑–Ω–∞—á–µ–Ω–∏—è –Ω–∞ –∫–æ–Ω—Å–æ–ª—å:

–≠—Ç–æ—Ç –∫–æ–¥ –ø—Ä–æ–≤–µ—Ä—è–µ—Ç, —è–≤–ª—è–µ—Ç—Å—è –ª–∏ –∑–Ω–∞—á–µ–Ω–∏–µ " get_key " –∫–ª—é—á–æ–º –≤ —Å–ª–æ–≤–∞—Ä–µ " raspberry_pi & rdquo ;. –ï—Å–ª–∏ –∫–ª—é—á —Å—É—â–µ—Å—Ç–≤—É–µ—Ç, –±—É–¥–µ—Ç –≤—ã–ø–æ–ª–Ω—è—Ç—å—Å—è –∏–Ω—Å—Ç—Ä—É–∫—Ü–∏—è " if " . –í –ø—Ä–æ—Ç–∏–≤–Ω–æ–º —Å–ª—É—á–∞–µ –±—É–¥–µ—Ç –∑–∞–ø—É—â–µ–Ω –æ–ø–µ—Ä–∞—Ç–æ—Ä " else & rdquo ;. –î–∞–≤–∞–π—Ç–µ –ø–æ–ø—Ä–æ–±—É–µ–º –ø—Ä–æ–≤–µ—Ä–∏—Ç—å –∏–Ω—Ñ–æ—Ä–º–∞—Ü–∏—é –æ –¶–ü –∫–æ–º–ø—å—é—Ç–µ—Ä–∞:

–î–∞–≤–∞–π—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏–º –∏–º—è –∫–æ–º–ø—å—é—Ç–µ—Ä–∞:

–ù–∞—à –∫–æ–¥ —Ä–∞–±–æ—Ç–∞–µ—Ç! –ö–æ–≥–¥–∞ –º—ã –∏—â–µ–º –Ω–µ—Å—É—â–µ—Å—Ç–≤—É—é—â–∏–π –∫–ª—é—á, –∫–æ–º–∞–Ω–¥–∞ " else " –≤—ã–ø–∏—Å–∫–∞ –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è. –≠—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –≤ –Ω–∞—à–µ–º –∫–æ–¥–µ –Ω–µ –º–æ–∂–µ—Ç –≤–æ–∑–Ω–∏–∫–Ω—É—Ç—å –æ—à–∏–±–∫–∞ KeyError, –ø–æ—Ç–æ–º—É —á—Ç–æ –º—ã –Ω–µ –ø—ã—Ç–∞–µ–º—Å—è –ø–æ–ª—É—á–∏—Ç—å –¥–æ—Å—Ç—É–ø –∫ –∫–ª—é—á—É –≤ " else " –±–ª–æ–∫.

–ù–∞—à –∫–æ–¥ —Ä–∞–±–æ—Ç–∞–µ—Ç! –ö–æ–≥–¥–∞ –º—ã –∏—â–µ–º –Ω–µ—Å—É—â–µ—Å—Ç–≤—É—é—â–∏–π –∫–ª—é—á, –∫–æ–º–∞–Ω–¥–∞ " else " –≤—ã–ø–∏—Å–∫–∞ –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è. –≠—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –≤ –Ω–∞—à–µ–º –∫–æ–¥–µ –Ω–µ –º–æ–∂–µ—Ç –≤–æ–∑–Ω–∏–∫–Ω—É—Ç—å –æ—à–∏–±–∫–∞ KeyError, –ø–æ—Ç–æ–º—É —á—Ç–æ –º—ã –Ω–µ –ø—ã—Ç–∞–µ–º—Å—è –ø–æ–ª—É—á–∏—Ç—å –¥–æ—Å—Ç—É–ø –∫ –∫–ª—é—á—É –≤ " else " –±–ª–æ–∫.

–ó–∞–∫–ª—é—á–µ–Ω–∏–µ

–û—à–∏–±–∫–∞ KeyError –≤–æ–∑–Ω–∏–∫–∞–µ—Ç, –∫–æ–≥–¥–∞ –≤—ã –ø—ã—Ç–∞–µ—Ç–µ—Å—å –ø–æ–ª—É—á–∏—Ç—å –¥–æ—Å—Ç—É–ø –∫ –∑–Ω–∞—á–µ–Ω–∏—é –∏–∑ –Ω–µ—Å—É—â–µ—Å—Ç–≤—É—é—â–µ–≥–æ —Å–ª–æ–≤–∞—Ä—è. –ß—Ç–æ–±—ã —É—Å—Ç—Ä–∞–Ω–∏—Ç—å –∫–ª—é—á–µ–≤—É—é –æ—à–∏–±–∫—É, –≤—ã –º–æ–∂–µ—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏—Ç—å –Ω–∞–ª–∏—á–∏–µ –∫–ª—é—á–∞ –∑–∞—Ä–∞–Ω–µ–µ, –ø—Ä–µ–∂–¥–µ —á–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –µ–≥–æ, –∏ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –µ–≥–æ —Ç–æ–ª—å–∫–æ –≤ —Ç–æ–º —Å–ª—É—á–∞–µ, –µ—Å–ª–∏ –∫–ª—é—á —Å—É—â–µ—Å—Ç–≤—É–µ—Ç. –î–ª—è –æ–±—Ä–∞–±–æ—Ç–∫–∏ –∫–ª—é—á–µ–≤–æ–π –æ—à–∏–±–∫–∏ –º–æ–∂–Ω–æ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –±–ª–æ–∫ try & hellip; "> –†—É–∫–æ–≤–æ–¥—Å—Ç–≤–æ –ø–æ –∏–∑—É—á–µ–Ω–∏—é Python . –í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –≤—ã –Ω–∞–π–¥–µ—Ç–µ —Å—Å—ã–ª–∫–∏ –Ω–∞ –ø–æ–ø—É–ª—è—Ä–Ω—ã–µ —É—á–µ–±–Ω—ã–µ —Ä–µ—Å—É—Ä—Å—ã, –∫–Ω–∏–≥–∏ –∏ –∫—É—Ä—Å—ã.

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method