CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 17 Jul 2025 14:52:03 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20080110063225
location: https://web.archive.org/web/20080110063225/https://wiki.python.org/moin/KeyError
server-timing: captures_list;dur=0.522913, exclusion.robots;dur=0.023156, exclusion.robots.policy;dur=0.014543, esindex;dur=0.011583, cdx.remote;dur=69.796668, LoadShardBlock;dur=397.810085, PetaboxLoader3.datanode;dur=169.726985, PetaboxLoader3.resolve;dur=178.495937
x-app-server: wwwb-app201
x-ts: 302
x-tr: 495
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: SERVER=wwwb-app201; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Thu, 17 Jul 2025 14:52:05 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Thu, 10 Jan 2008 06:32:24 GMT
x-archive-orig-server: Apache/2.2.3 (Debian) mod_fastcgi/2.4.2
x-archive-orig-pragma: no-cache
x-archive-orig-cache-control: no-cache
x-archive-orig-expires: -1
x-archive-orig-vary: Accept-Language,Cookie,User-Agent
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Thu, 10 Jan 2008 06:32:25 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 08 Nov 2005 04:46:52 GMT", ; rel="prev memento"; datetime="Fri, 09 Nov 2007 17:59:51 GMT", ; rel="memento"; datetime="Thu, 10 Jan 2008 06:32:25 GMT", ; rel="next memento"; datetime="Sun, 30 Mar 2008 23:59:18 GMT", ; rel="last memento"; datetime="Thu, 09 Jan 2025 02:11:28 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_1_20080110050741_crawl107-c/52_1_20080110063055_crawl107.arc.gz
server-timing: captures_list;dur=0.832689, exclusion.robots;dur=0.038472, exclusion.robots.policy;dur=0.022476, esindex;dur=0.016616, cdx.remote;dur=120.102857, LoadShardBlock;dur=1173.391422, PetaboxLoader3.datanode;dur=417.657565, PetaboxLoader3.resolve;dur=869.273888, load_resource;dur=258.173569
x-app-server: wwwb-app201
x-ts: 200
x-tr: 1630
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
KeyError - PythonInfo Wiki
Python raises a KeyError whenever a dict() object is requested a value using format a = adict[key] if key is not in the dictionary.
If you don't want to have an exception but default value used instead, you can use get() method:
1 default = 'Scruffy'
2 a = adict.get('dogname', default)
Even more handy is somewhat controversially-named setdefault(key, val) which sets the value of key only if it is not already in the dict, and returns the value in any case:
1 default = 'Scruffy'
2 dog_owned_by = {'Peter': 'Furry', 'Sally': 'Fluffy'}
3
4 dogs = []
5 for owner in ('Peter', 'Sally', 'Tim'):
6 dogs.append(dog_owned_by.setdefault(owner, default))
7
8 # dogs == ['Furry', 'Fluffy', 'Scruffy']
EditText (last edited 2005-09-14 10:11:27 by EdvardMajakari)