Skip to main content

Home/ Mac Attack/ Group items tagged argument

Rss Feed Group items tagged

Benjamin Bandt-Horn

jcalderone: How to override comparison operators in Python - 0 views

  • here are the basic rules for the customization of ==, !=, <, >, <=, and >=: For all six of the above operators, if __cmp__ is defined on the left-hand argument, it is called with the right-hand argument. A result of -1 indicates the LHS is less than the RHS. A result of 0 indicates they are equal. A result of 1 indicates the LHS is greater than the RHS
  • __eq__ is not used for !=
  • For <, __lt__ is used. For >, __gt__. For <= and >=, __le__ and __ge__ respectively
  • ...1 more annotation...
  • __eq__ does an isinstance test on its argument
  •  
    here are the basic rules for the customization of ==, !=, , =: For all six of the above operators, if __cmp__ is defined on the left-hand argument, it is called with the right-hand argument. A result of -1 indicates the LHS is less than the RHS. A result of 0 indicates they are equal. A result of 1 indicates the LHS is greater than the RHS.
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

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

Mac OSX : How to burn an ISO image to a USB key - The Endless Geek - 0 views

  •  
    If you have tried to create a bootable USB key from an iso image in Mac OSX using Disk Utility then you have probably encountered the frustrating and almost Windows-like cryptic error message "Could not validate source - Invalid argument" error. Looking in the system log via the Console app I suspect this is because internally DiskUtil tries to run /usr/sbin/asr to verify the image, which fails.   1 2 3 $ asr imagescan --source ubuntu-rescue-remix-12-04.iso only UDIF and NDIF images can be scanned. asr: image scan failed - Invalid argument. UDIF and NDIF are image formats used by Apple, and Disk Utility is pretty hopeless with anything that falls outside of these standards. The iso standard is short for ISO9660 and is a standard that defines the format of an image intended for burning to CD. Even after using hdutil to convert the image to UDRO (a UDIF Read-Only image) Disk Utility will still stubbornly refuse to help. Disk Destroyer Duplicator to the rescue Being Unix based, OSX has the command line dd utility available. Short for Disk Duplicator, dd is a block level reader/writer that makes raw copies from one file to another. But you want to copy the image to a device, right? That's fine, because everything in the world of Unix/Linux is a file - even devices. Informally referred to as Disk Destroyer, should you tell dd to output to the wrong device then your day is definitely going to be spoiled, so to avoid any mishaps we will make sure we know which devices on your system is your USB stick. You can determine this from the command line:
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

Function overloading in Python: Missing - Stack Overflow - 0 views

  • keyword arguments with default values can go a long way.
  • In Python, I think it's more accepted to use duck typing -- asking what an object can do, rather than what it is
  • it goes against the spirit of Python to worry a lot about what types are passed into methods
  •  
    keyword arguments with default values can go a long way.
Benjamin Bandt-Horn

!performance - Python string formatting: % vs. .format - Stack Overflow - 0 views

  • which is just ugly. .format doesn't have those issues. Also in the second example you gave, the .format example is much cleaner looking.
  •  
    .format just seems more sophisticated in many ways. You can do stuff like re-use arguments, which you can't do with %. An annoying thing about % is also how it can either take a variable or a tuple
Benjamin Bandt-Horn

Classes & Iterators - Dive Into Python 3 - 0 views

  • Comprehensions are just a simple form of iterators. Generators are just a simple form of iterators
  • The first argument of every class method, including the __init__() method, is always a reference to the current instance of the class. By convention, this argument is named self.
  • self is not a reserved word in Python, merely a naming convention
  • ...6 more annotations...
  • To build an iterator from scratch, Fib needs to be a class, not a function.
  • in most cases), __iter__() simply returns self, since this class implements its own __next__() method.
  • a for loop will call this automatically, but you can also call it yourself manually
  • the __next__() method raises a StopIteration exception, this signals to the caller that the iteration is exhausted. Unlike most exceptions, this is not an error; it’s a normal condition that just means that the iterator has no more values to generate. If the caller is a for loop, it will notice this StopIteration exception and gracefully exit the loop. (In other words, it will swallow the exception.)
  • Do not use yield here; that’s a bit of syntactic sugar that only applies when you’re using generators. Here you’re creating your own iterator from scratch; use return instead
  • raise StopIteration
  •  
    Comprehensions are just a simple form of iterators. Generators are just a simple form of iterators
1 - 8 of 8
Showing 20 items per page