Tag Info

Hot answers tagged

5

I am unfamiliar with the Greg Stein Python fork, so discount this comparison as speculative historical analogy if you wish. But this was exactly the historical experience of many infrastructure codebases moving from single- to multi-threaded implementations. Essentially every Unix implementation I studied in the 1990s--AIX, DEC OSF/1, DG/UX, DYNIX, HP-UX, ...


5

The generally accepted view of things is that "app builder" sort of software development can be okay when the builder is focused on a very specific domain (RPG builder, Excel wizards, basic HTML builders, "programming for kids") but become problematic as soon as you try to do anything outside of that. These problems usually come in two flavors. The first is ...


3

Bags and suitcases are both types of containers. You can also put bags inside suitcases, and vice versa. Containment doesn't care about inheritance, and inheritance doesn't care about containment. The two concepts are entirely orthogonal, and as such there is no 'best practice' here.


2

Everything in Python is an object, including classes. This means you can reference classes, passing them around like arguments, store them in attributes, (extra) names, lists, dictionaries, etc. This is perfectly normal in Python: class_map = { 'foo': A, 'bar': SomeOtherClass, 'baz': YetAnother, } instance = class_map[some_variable]() Now ...


2

It just keeps a cache of small integer instances. >>> a = 58435 >>> b = 58435 >>> a is b False Precisely how small is easy to determine manually for your implementation. Mine caches −5 to 256.


2

No, this is not just a Python problem. Resolving the question of "has this object been modified since X happened?" (in this case, the object being added to the dictionary) would require one of two things. Either you use immutable objects, in which case the answer is always "no" and the question is rather meaningless, or you have some way to note when an ...


2

It is typical to compare floats using a tolerance, rather than by equality. This both avoids some of the issues with floating point arithmetic on computers and allows you to specify an appropriate level of precision. In your case, if you only care about hundredths of a unit: if abs(speed - limit) < 0.01: ... For example: >>> abs(0.0 - ...


1

It depends. In some languages (like Java), you don't really have a choice because every class (except Object) is a subclass. If class C needs some functionality from class B to do its work, but you can't describe instances of class C as also being instances of class B (C can't work as a drop-in replacement for B), then your design is absolutely correct.


1

You pretty much answered the question yourself, and in a way that confirms my own experience: A python wrapper is better in all accounts except for speed and memory efficiency. You are not telling us what sort of application is that so you'll need to carefully weigh how important those factors are for you. In my experience, most of the time they matter very ...


1

It's perfectly doable, even in Python. The trick is in returning a wrapper instead of the original stored object. in your example: d['xx'] = range(4) d['xx'].append(5) the second line can be extended into a retrieve and an operation: d['xx'] = range(4) t = d['xx'] t.append(5) and it's obvious that t doesn't notify d about the .append() operation. ...


1

As far as I know Pandas is not the best tool if you can not store everything in the memory. Additionally you are creating some extra data that you might try to avoid. I'm talking about the list comprehensions. For once they are a bit too big/complex to be a list comprehension as for me. Secondly due to the its nature for short period of time your are ...


1

It is a bit unclear in your question whether you ask about how to parallelize the Random Forests™ 1 algorithm, or you ask which other algorithm would perform better. On the first issue, it seems that the Random Forests™ algorithm is embarrassingly parallel, and that there is a readily parallel implementation of the algorithm within scikit-learn, ...


1

Try using decimal module. It allows to manipulate precision. With local context you should get enough flexibility. Example taken from docs: from decimal import localcontext with localcontext() as ctx: ctx.prec = 42 # Perform a high precision calculation s = calculate_something() s = +s # Round the final result back to the default precision ...



Only top voted, non community-wiki answers of a minimum length are eligible