[Python-Dev] I'd like list.pop to accept an optional second argument giving a default value

Jim Fulton jim@digicool.com
Thu, 22 Jul 1999 08:15:08 -0400


I like the list pop method because it provides a way to use
lists as thread safe queues and stacks (since append and pop
are protected by the global interpreter lock).

With pop, you can essentially test whether the list is 
empty and get a value if it isn't in one atomic operation:

  try: 
      foo=queue.pop(0)
  except IndexError:
      ... empty queue case
  else:
      ... non-empty case, do something with foo

Unfortunately, this incurs exception overhead. I'd rather do 
something like:

  foo=queue.pop(0,marker)
  if foo is marker: 
      ... empty queue case
  else:
      ... non-empty case, do something with foo

I'd be happy to provide a patch.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.