Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's a locals() example from apsw:

  # You can use local variables as the dictionary
  title="..."
  isbn="...."
  cursor.execute(sql, locals())
In the pre-dataclass / pre-namedtuple days I would use:

  class Spam:
    def __init__(a=1, b=2, c=3, d="four", .. lots args ..):
      self.__dict__.update(locals())
      del self.self
in prototype code. But that wouldn't go into production. (I wouldn't put the namedtuple version in production either.)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: