Better HN
topnewbestaskshowjobs
Log inSign up

macbony

3 karma · joined Oct 1, 2012 (14y ago) · 11 submissions

Software engineer at DecisionDesk.com
Submissions

comment 11y ago · link · parent

The problem is you, like an overweight person, think that you can get by with an economy ticket. I feel bad for your knees, but I'm reclining because I paid for the ability to recline even if it's only a few inches. If you are uncomfortable in your seat, fly a different airline or upgrade.

comment 11y ago · link · parent

The Super Bowl is the only "Big Game" they refer to in the ads. Sure there are other "big games", but these are Super Bowl ads pure and simple.

comment 12y ago · link · parent

C-a a is an extra keypress but good enough for me.

comment 12y ago · link · parent

No, the reason it exists is so you can override functionality of subclasses at run time, otherwise things like monkey patching would be impossible. I guess it COULD do a pass to see if the attr is an immutable or some form of primative type when __new__ is called and force those to be instantiated as instance attributes at the cost of internal consistency, but it seems pretty straight forward to me the way it works now. You don't need to be an expert, you just need a basic understand of how Python evaluates code and the difference between tags and variables.

comment 12y ago · link · parent

I'm not really sure I understand your point. The value of x is still going to be in memory, but you may not have any references to it and it will be garbage collected. The disconnect is in thinking x is a variable and not an identifier. x points to the object in the parent until it is overridden. This allows me to dynamically alter the functionality of a class and all it's subclasses that don't override that functionality during runtime.

comment 12y ago · link · parent

x isn't a variable, it's a tag. Because Python is dynamically typed, x can be an int one minute and a function the next, so every attribute on a class is stored as a pointer to an object, including attributes that are integers (which is an object) and functions (which are also objects). Because you aren't declaring the type of x (Python doesn't allow that), Python has to treat x = 1 the same way it'd treat def x(self).

comment 12y ago · link · parent

If instead of x being an integer, it were a function x(), then it makes more sense. Really, for Python, there is no difference between the two in this example. When you assign a new value to B.x, you're overriding the value that B inherited from A. When you override the value in A, any subclass that doesn't have it's own overridden value will use the new A.x, but any subclass that is overridden will be unchanged.

comment 12y ago · link · parent

I prefer

  print("A {0} can be very cute!".format(pet))
.format() is very versatile.

  d = {'first': 'Robert', 'last': 'Paulson'}
  print("His name was {first} {last}!".format(**d))
  >> His name was Robert Paulson!


  class Person:
      def __init__(self, first, last):
          self.first, self.last = first, last

  p = Person('Robert', 'Paulson')
  print("His name is {0.first} {0.last}!".format(p))
  >> His name was Robert Paulson!
You also do not need to know what type is being passed in as the __str__ method is used for .format().

comment 13y ago · link · parent

That's where this one comes in?

comment 14y ago · link · parent

:t is the "copy" version of the command. It's shorter than :co[py].