Tag Info

New answers tagged

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.


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.


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 ...


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, ...


0

Don't subclass shelve.Self, instead define a new class with a constructor that that calls shelve.open. Implement the method of interest by calling the actual methods on the returned shelf object.


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. ...


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 ...


0

Bit manipulation in Python is possible (if you mean the standard bit operations like AND OR XOR etc.), but you cannot change arbitary memory by design. You can use Cython (http://cython.org/) however, which is a extended dialect of Python which compiles to C.


-1

Another wild hypothesis: In 1999 Linux and other Unices hadn't a performant synchronisation like it has now with futex(2) (http://en.wikipedia.org/wiki/Futex). Those came around 2002 (and were merged into 2.6 around 2004). Since all builtin data structures has to be synchronized locking costs a lot. Ӎσᶎ already pointed out, that atomic operations are not ...


-1

It is definitely okay and I would encourage you to have several classes in one file as long as they are realated. In general your classes should stay short and concise and you should rather split up behaviour in two or more classes than build huge monolithic ones. When writing several small classes it is really necessary and helpful to keep those that are ...


-3

In short - hell yes. Moreover, having multiple classes in a single file is sometimes very handy. Some packages (six, bottle) explicitly ship in a single file in order to easily be integrated into any third-party module without being pip installed (sometimes desirable). But, do make sure to organise your code well. Intensively use code comments and ...


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 ...


0

As MichaelT pointed out you need to be clear on metrics that you are trying to measure and the ones that make sense to you. Some common metrics when it comes to measuring network performance are Throughput. Latency. Server and client response time. In my opinion just measuring RTT is not sufficient to measure performance of routing because the RTT is ...


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 ...


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 ...


0

is operator is not the same as ==. While == checks the value of object, is checks identity of it using it's memory address. As mentioned before ints from -5 to 256 (inclusive) are special (small) and Python will not recreate those objects. Ints from outside that range will be new objects every time so is will return True only if they are the same exact ...


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.


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, ...


0

After some research it becomes clear, that pywebsockets was developed for testing browser implementations. It has (at least) the drawbacks of being neither secure nor scalable. So in short: It is not suitable to be used in production environment! As stated above it is still a great tool for testing your client side implementation of websockets, probably ...


0

No, it's a bad idea to use in production unless you thoroughly understand what the package does and you're willing to take the associated risks from running experimental code in a production environment. As you mentioned, their site clearly states it is not for production usage. pywebsocket is intended for testing or experimental purposes. So if you ...


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 - ...


0

Don't speak Python, but the idea seems fairly simple: you pick the element in the middle and its left (or right) neighbour, A and B you compare those elements A and B against each other if B < B, choose A as new E, and start over if A >= B, choose B as new S, and start over at some point you are left with only 1 element, which is the minimum ...


0

Since either the first or last element would have to be the lowest, how about this? I even provide a key argument def min_convex(a_list, key=None): if key: first, last = key(a_list[0]), key(a_list[-1]) else: first, last = a_list[0], a_list[-1] if first < last: return first else: return last EDIT: well ...


2

Why are you optimizing? You seem to be concerned about memory usage. Why? Is the projected savings large enough to let you rent a cheaper VM? Is the sites' current usage threatening to bust your machine's current RAM? (And even if they are, are you confident that your going to spend less on development time for this feature than you would for just ...


0

I suggest putting your code into git, then using submodules to load your 'library' of shared code. If you read up on it, this sounds like exactly what you need: http://git-scm.com/book/en/Git-Tools-Submodules It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party ...



Top 50 recent answers are included