News for hackers. Stuff that matters.
Re:Show HN: Pydb – a lightweight database with Python syntax... by reubano on Wednesday February 01, 2017 @01:56AM (#13538909)
This is the pythonic way

  def func(*args, defaulted='default', **kwargs):
      # args is a list, kwargs is a dict
      arg0 = args[0] if args else None
      another_kwarg = kwargs.get('another_kwarg', 'default')
      print(arg0, defaulted, another_kwarg)


  >>> func('one', 'two', defaulted='myval')
  one myval default
  >>> func(another_kwarg='myval')    
  None default myval
  >>> args = ('one', 'two')
  >>> kwargs = {'defaulted': 'myval', 'another_kwarg': 'other'}
  >>> func(*args, **kwargs)    
  one myval other

There are no comments on this comment yet.