KeyError

Doran_Dermot at emc.com Doran_Dermot at emc.com
Thu Dec 16 06:10:03 EST 2004


If a default value would be acceptable to the application (which is quite
likely), then this would be a much cleaner solution.

-----Original Message-----
From: python-list-bounces+doran_dermot=emc.com at python.org
[mailto:python-list-bounces+doran_dermot=emc.com at python.org] On Behalf Of
Roland Heiber
Sent: 16 December 2004 10:28
To: python-list at python.org
Subject: Re: KeyError

Doran_Dermot at emc.com wrote:
> Hi "R",
> 
> The only explanation I can give is that the environment varialbe
REMOTE_ADDR
> does not exist!  Wrap your high-level code with try and except. Example:
> try:
>  tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
> except KeyError:
>   # Code to  handle the fact tht REMOT_ADDR does not exist. 

... or just replace os.environ['REMOTE_ADDR'] with 
os.environ.get('REMOTE_ADDR', 'enter_default_here') to use a default in 
case of missing REMOTE_ADDR ...

HtH, Roland
-- 
http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list