Sessionhandling

Lutz Schroeer ifls at rz.tu-clausthal.de
Tue Sep 24 03:16:50 EDT 2002


Alan Kennedy <alanmk at hotmail.com> wrote:
: try:
:    langpref = os.environ['HTTP_ACCEPT_LANGUAGE']
:    langs = string.split(langpref, ',')
:    firstpref = langs[0]
:    secondpref = langs[1]
:    thirdpref = langs[2]
: except:
:    firstpref = 'en-ie'

This does not work, does it? If the user defined only _two_ preferred
languages you will get an exception by trying to evaluate the third language
and "firstpref" will become "en-ie", whatever it has been set to before.

Here's my modification to the code:

langpref = os.environ['HTTP_ACCEPT_LANGUAGE']    
firstpref = 'en-ie'  
try:
  langs = string.split(langpref, ',')
  firstpref = langs[0]
  secondpref = langs[1]
  thirdpref = langs[2] 
except:
  pass

Lutz



More information about the Python-list mailing list