47 'children': [],
48 }
49
50 def find_id(_id, e=sidebar):51 if 'id' in e and e['id'] == _id:
52 return e
53 for c in e.get('children', []):
33 Don't forget to call :func:`.load()` afterwards.
34 """
35
36 def __init__(self, modules=[], loadpath=None): 37 augeas.Augeas.__init__(self, loadpath=loadpath, flags=augeas.Augeas.NO_MODL_AUTOLOAD | augeas.Augeas.NO_LOAD)
38 for module in modules:
39 path = f'/augeas/load/{module["name"]}'
Do not use a mutable like list
or dictionary
as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.
def my_function(elem, l=[]):
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [2, 5]
def my_function(elem, l=None):
if l is None:
l = []
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [5]