Order(product, qty) a classmethod factory from_line(cls, line) that parses 'pen x3'-style strings (product, space, x, quantity) into an instance. Factories as classmethods keep parsing logic on the class and play well with subclassing (they receive cls, not a hardcoded name).o = Order.from_line('pen x3'); (o.product, o.qty)('pen', 3)The string is parsed and forwarded to the real constructor.
line.rsplit(' x', 1) splits product from count.
Return cls(product, int(qty)).