Question about idioms for clearing a list

2006-01-31 Thread Steven Watanabe
I know that the standard idioms for clearing a list are:

  (1) mylist[:] = []
  (2) del mylist[:]

I guess I'm not in the "slicing frame of mind", as someone put it, but 
can someone explain what the difference is between these and:

  (3) mylist = []

Why are (1) and (2) preferred? I think the first two are changing the 
list in-place, but why is that better? Isn't the end result the same?

Thanks in advance.
--
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Why does built-in set not take keyword arguments?

2006-05-04 Thread Steven Watanabe
I'm trying to do something like this in Python 2.4.3:

class NamedSet(set):
  def __init__(self, items=(), name=''):
set.__init__(self, items)
self.name = name

class NamedList(list):
  def __init__(self, items=(), name=''):
list.__init__(self, items)
self.name = name

I can do:

>>> mylist = NamedList(name='foo')

but I can't do:

>>> myset = NamedSet(name='bar')
TypeError: set() does not take keyword arguments

How come? How would I achieve what I'm trying to do?
Thanks.
--
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list


Don't want child process inheriting open sockets

2008-01-22 Thread Steven Watanabe
I'm using subprocess.Popen() to create a child process. The child process is 
inheriting the parent process' open sockets, but I don't want that. I believe 
that on Unix systems I could use the FD_CLOEXEC flag, but I'm running Windows. 
Any suggestions?
-- 
http://mail.python.org/mailman/listinfo/python-list

Comparisons and singletons

2006-03-25 Thread Steven Watanabe
PEP 8 says, "Comparisons to singletons like None should always be done
with 'is' or 'is not', never the equality operators." I know that "is"
is an identity operator, "==" and "!=" are the equality operators, but
I'm not sure what other singletons are being referred to here.

Also, I've seen code that does things like:

  if foo is 3:
  if foo is not '':

Are these valid uses of "is"?

Thanks in advance.
--
Steven.
-- 
http://mail.python.org/mailman/listinfo/python-list