RE: KeyError

Discussion in 'Python' started by Doran_Dermot@emc.com, Dec 16, 2004.

  1. Guest

    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=
    [mailto:python-list-bounces+doran_dermot=] On Behalf Of
    Roland Heiber
    Sent: 16 December 2004 10:28
    To:
    Subject: Re: KeyError

    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
    , Dec 16, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Norman Shelley
    Replies:
    0
    Views:
    271
    Norman Shelley
    Oct 11, 2003
  2. Ajay
    Replies:
    5
    Views:
    575
    Uche Ogbuji
    Sep 12, 2004
  3. Guest

    KeyError

    Guest, Dec 15, 2004, in forum: Python
    Replies:
    1
    Views:
    1,858
    Diez B. Roggisch
    Dec 15, 2004
  4. Frans Englich

    Re: KeyError

    Frans Englich, Dec 15, 2004, in forum: Python
    Replies:
    0
    Views:
    351
    Frans Englich
    Dec 15, 2004
  5. RE: KeyError

    , Dec 15, 2004, in forum: Python
    Replies:
    1
    Views:
    452
    Roland Heiber
    Dec 16, 2004
Loading...

Share This Page