anomalous behaviour of bc.homogenize() with list comprehension


196
views
0
12 months ago by
Consider bcs is a list of  DirichletBC instances.
If I do
      bcs_h = [bc.homogenize() for bc in bcs]
      for  bc in bcs_h:
           print type(bc)
It gives <type 'NoneType'>

But if I do
       bcs_h =[]
       for bc in bcs:
            bc.homogenize()
            bcs_h.append(bc)
then each element of bcs_h  seems to be <class 'dolfin.fem.bcs.DirichletBC'>

In both cases, bcs_h is obtained by bc.homogenize(), but why is it NoneType in first case ?

1 Answer


2
12 months ago by
pf4d 
Clearly, bc.homogenize() returns None.
So bc.homogenize() changes bc in-place  but returns None ?
written 12 months ago by Shriram S 
Well, strictly speaking homogenize() is an instance method so "in-place" does not apply.  Python functions without a "return" clause return "None" by default.
written 12 months ago by pf4d 
Please login to add an answer/comment or follow this question.

Similar posts:
Search »