Hot answers tagged

17

What semantic features of Python (and other dynamic languages) contribute to its slowness? None. Performance of language implementations is a function of money, resources, and PhD theses, not language features. Self is much more dynamic than Smalltalk and slightly more dynamic than Python, Ruby, ECMAScript, or Lua, and it had a VM that outperformed all ...


7

While Python's current implementation (which lacks a lot of the optimisations performed by other dynamic languages, e.g. modern Javascript implementations and, as you point out, Lua) is a source of most of its problems, it does have some semantic issues that would make it difficult for an implementation to compete with other languages, at least in certain ...


5

There's a couple of ways you can do this: You can use isinstance to determine what the object's class is: if isinstance(foo, bar): do_something() elif isinstance(foo, baz): do_something_else() else: default_behavior() However, this gets unwieldy quickly with a large number of possible classes, and isn't good OOP. The OOP way would be to use ...


3

After doing some legwork, downloading the last package that was available for the library the only licensing information I found was in the PKG-INFO file: License: PSF or ZPL Which makes me believe you can choose either. After 10 years of neglect, efforts to contact the author may not go well, but it's worth attempting any obvious action you can. ...


3

I am assuming you are aware of Python's built-in sort and are simply asking this as a learning exercise. (If you just want to use the 'best' sort, use Python's built-in sort function. It is heavily optimised and will be faster than anything you implement in Python.) The short answer is, your quicksort function has a bug, and if you fix it then it will work ...


2

No. The key word here is "nonexclusive" license. It means that you're granting them the right to distribute your code, (which is the entire point of putting it up on a package manager,) without setting up any sort of exclusive deal or transfer of rights with them. And as the license is to distribute your code, rather than to use it, it doesn't conflict ...


2

According to the Classes section of the Python docs: “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a ...


2

This applies to any language. If you don't plan on doing anything with the exception, or as a result of the exception being caught, then don't bother catching it. It saves you a few lines of code and indentation. Seeing an except block could tell other programmers, who are busy and aren't reading every line of code, "Oh good. CrazyPython is handling this ...


2

If you indeed want other developers to work on the actual code, then yes, source control is the solution. If you want control over what goes in, then indeed PR's seem like the correct choice. If you use GitHub you can provide comments before merging a PR


2

A variable should always have the smallest scope and the shortest lifetime possible. Therefore a class member is preferable to a global variable, and a local variable or parameter is preferable to a class member. In your example, TempWAP is only used inside the execution of process_packet_capture() and could therefore be changed to a local and passed as a ...


2

Don't use classes and or member variables when they are not needed. As soon as you need them, well, use them. I'm serious.


2

However, I initialize it without passing parameters for the constructor. Is that defeating the purpose? No, absolutely not. Handler, maybe misnamed, but in a sense it represents a collection object, which is perfectly reasonable without constructor parameters. A collection object maintains some state for it's duration, and, many collections are created ...


1

No, bytecode files do not contain mnemonics. Mnemonics are textual representations for instructions of a (virtual/bytecode) processor and are an integral part of assembly languages. Bytecode files are not meant to be read by humans and thus are typically binary files that directly contain the machine-code (binary) instructions for the bytecode processor.


1

... perhaps there would be issues that would take time to resolve Most certainly there would be issues. Python is a general purpose language. Matlab is specialized. This keeps you out of the weeds. Sure you can't wander off anywhere you want but that is what keeps things moving. There may be many Python libraries that approximate what matlab does to ...


1

This is what non-functional requirements of performance are for. The notion of fast enough has nothing technical per se. It depends on user perception of your product, and should be translated through the requirements. This is the only objective way for you to tell whether your actual implementation is fast enough or not. If you don't have those ...


1

You have forgotten the most basic question: Is the speed satisfactory for the use case? If the answer is "yes" -> don't profile If no, you might look at your table. But honestly, it looks not terribly useful, because almost all time is spend in OBSparser.py:48(parse), which takes a LONG time. I would suggest you refactor that method into several ...


1

This is the difference between an immutable object (as Python numbers are) and a mutable object (as Numpy matrices are). When you perform an operation on an immutable object, a new copy is made, and your variable is updated to refer to the new copy: x = 0 ... x = 7 First a '0' object is created, and 'x' is set to refer to it. Then a '7' is created, and '...


1

Don't get too caught up with the way things are usually done, an API can be restful without having to have resource identifier specified in the URL. In your case I would say its perfectly acceptable to place the path(s) in the POST body.


1

If you want to get real CPU parallelization as Mason stated you need to get around GIL by forking instead of using threads. This has extra overhead compared to threads but it may work if the process time is the bottleneck. The best way to achieve this in a non-hacky way is to use multiprocess.Pool and use a variant of map. This will dispatch your iterable ...


1

A sentinel and a defaulted arg is a good way to do it. I would use an arbitrary object though, not a list (preference, and this way someone won't go about fiddling with it). class A(object): _DEFAULT = object() def __init__(self): self._size = 0 def sizeC(self, arg=_DEFAULT): if arg is not DEFAULT: self._size = arg ...



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