Skip to main content

Home/ Mac Attack/ Group items tagged args

Rss Feed Group items tagged

Benjamin Bandt-Horn

python - *args and **kwargs? - Stack Overflow - 0 views

  •  
    One case where *args and **kwargs are useful is when writing wrapper functions (such as decorators) that need to be able accept arbitrary arguments to pass through to the function being wrapped. For example, a simple decorator that prints the arguments and return value of the function being wrapped: def mydecorator( f ):   @functools.wraps( f )      def wrapper( *args, **kwargs ): ...
Benjamin Bandt-Horn

operators - What is the name of ** in python? - Programmers Stack Exchange - 0 views

  • It's not an operator as such, so it doesn't really have a name, but it is defined as a "syntactic rule". So it should be called: "the keyword argument unpacking syntax"
  • # usually a tuple, always an iterable*
  • # usually a dict, always a mapping*
  • ...4 more annotations...
  • kwargs
  • args =
  • *: Iterables are objects that implement the __iter__() method and mappings are objects that implement __iter__() and __getitem__()
  • If you are unsure what to call a particular operator or if it is unnamed, you can always resort to Waka Waka Bang Splat as a reference to help you figure out what to call it. In this case for ** I would call it double-splat, though there are some alternate names for symbols.
  •  
    It's not an operator as such, so it doesn't really have a name, but it is defined as a "syntactic rule". So it should be called: "the keyword argument unpacking syntax"
Benjamin Bandt-Horn

4. More Control Flow Tools - Python v2.7.6 documentation - 0 views

  • *name must occur before **name.
  • keys = sorted(keywords.keys()) for kw in keys: print kw, ":", keywords[kw]
  • Note that the list of keyword argument names is created by sorting the result of the keywords dictionary’s keys() method before printing its contents; if this is not done, the order in which the arguments are printed is undefined
  • ...11 more annotations...
  • They are syntactically restricted to a single expression
  • Like nested function definitions, lambda functions can reference variables from the containing scope
  • Coding Style
  • CamelCase for classes
  • lower_case_with_underscores for functions and methods
  • Always use self as the name for the first method argument
  • comments
  • docstrings
  • separate
  • 79 characters
  • 4-space indentation, and no tabs
  •  
    keys = sorted(keywords.keys()) for kw in keys: print kw, ":", keywords[kw]
Benjamin Bandt-Horn

The new print function in Python 3.x - Stack Overflow - 0 views

  • If print() is a function, it would be much easier to replace it within one module (just def print(*args):...) or even throughout a program (e.g. by putting a different function in __builtin__.print). As it is, one can do this by writing a class with a write() method and assigning that to sys.stdout -- that's not bad, but definitely a much larger conceptual leap, and it works at a different level than print.
1 - 5 of 5
Showing 20 items per page