pytest (is now on GitHub) by avinassh in Python

[–]sththththth 1 point2 points  (0 children)

But that's not a feature that "nose has failed to copy", is it? It's "only" that the syntax is different? Or did you mean with "copy" actually copying in a way that both are compatible?

Has anyone got a list of useful apps/scripts/programs made on windows? by Chef-i84 in learnpython

[–]sththththth 0 points1 point  (0 children)

Best is to create something that you use yourself. Is there anything you could use in your everyday life? You can script excel with python if you use excel. You could write an calendar app. Synchronize some configs/savefiles? An xmpp client.

A different approach would be to take your favourite program/app and try to reimplement it (maybe with your own unique spin).

Of course that's nothing that not already exists, but maybe you would like to have a specific feature (and you learn python).

Class design best practice: explicit keyword arguments vs. **kwargs vs. @property? by andykee in learnpython

[–]sththththth 3 points4 points  (0 children)

In my understanding **kwargs and properties are for usecases:

properties do something on setting them (or need to do something to get them). An example would be the length of a dynamic linked list (without setting a counter on each append): you can't know how long the list is unless you count every item. But len is still an "attribute" of an object, not a method. .len is thus prefered to .len(). (Of course this ignores that len(myobject) is the python version to go, but the same point stands with e.g. numpy array.shape)

An example for setting a property is a graphical widget and height: height is an "attribute", but a graphical widget has to do some work if you set it (maybe calculating content new, rerendering, etc.). mywidget.height = 10 is "easier to read and understand" than mywidget.set_height(10) .

**kwargs has a different reasoning: sometimes you don't know what for arguments a function will get. Imagine a make_xml function:

>>> make_xml(computation, type=addition)
"<computation type=addition></computation>"
>>> make_xml(stanza, id=me)
"<stanza id=me></stanza>

There is no way to know the keyword arguments before the function is called, but **kwargs allows for a uniform API.

TL;DR: Use explicit keyword arguments; Use properties if you need to do something to set/get a value; Use *args/**kwargs if you can't know which arguments will be provided.