Tag Info

Hot answers tagged

9

Programs which require real-time number crunching (such as digital audio workstations or video players) have what I call a "computational threshold." What that means is that the choice of programming language can matter when there is not enough hardware horsepower to satisfy the necessary computational load, if the language itself is consuming a substantial ...


9

You can just ask Python herself: def is_python_pass_by_value(foo): foo.append('More precisely, for reference types, it is call-by-object-sharing.') foo = ['Python is pass-by-reference.'] quux = ['Yes, of course, Python *is* pass-by-value!'] is_python_pass_by_value(quux) print(quux) # ['Yes, of course, Python *is* pass-by-value!', 'More precisely, ...


9

Is Python interpreted (like Javascript or PHP)? is worth a read for more information and it says: ...different implementations of languages may do different things. These days you can find both C interpreters and Javascript compilers. Compiled and interpreted are descriptions of an implementation, not of a language; Their usage in relation to ...


7

This is a bit of a simplification, but there are three main steps in compiling code: Parse the source code to a syntax tree Compile the syntax tree into machine-independent byte code Translate byte code to machine code A C compiler does all three, and is without doubt a compiler. A Java compiler does 1 and 2, producing .class files, and the runtime does ...


6

Since you tagged this with python, I'll give you the Python perspective on this. In Python, this is entirely normal. Attributes are not private, they are merely marked as 'internal', by convention, by using a leading underscore. So _store is something that is 'internal' to the class, just as the implementation of __eq__ is an internal matter. You are not ...


4

In terms of official documentation, per the Programming FAQ: Remember that arguments are passed by assignment in Python. Elsewhere in the docs: The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is ...


4

Unlike .NET and Java, there is not a well-defined standard for python byte code, and they sometimes change it from version to version. See also this question. This has the implication that you can't really distribute the compiled version of your code, which in turn means, that you can't really consider it a compiled language.


4

An explicit check of the callback's ability to handle parameters is about the best you're going to be able to do. Python may be loosie-goosie in its duck typing, but it will complain and raise a TypeError exception if you feed a function the wrong number of parameters. No ifs, ands, or buts about that. You have existing functions in the field that you don't ...


4

Python is a dynamically-typed language. This has two important consequences: The compiler is unable to reject certain kinds of logical error at compile time which would be caught by a C++ compiler Because the types of some (even most) variables cannot be determined at compile time, operations on those variables must be implemented by dynamically ...


3

In Python, it's "Easier to ask for forgiveness than permission" - it is common "Pythonic" practice to use exceptions and error handling, rather than e.g. if checking up-front ("Look before you leap") to handle potential problems. The documentation provides a few examples that demonstrate where the latter can really cause problems - if the situation changes ...


3

It’s an expression statement. In the REPL, the repr of the result of an expression statement is printed if it’s not None. You use this type of statement all the time when calling functions: f(x) It’s just that those functions typically have side effects, whereas literals do not. This is a common syntactic feature of imperative languages with a ...


3

In Python 2, you cannot put a keyword argument after *args, that's a syntax error: >>> import sys >>> sys.version_info sys.version_info(major=2, minor=7, micro=8, releaselevel='final', serial=0) >>> def random_product(*args, repeat=1): File "<stdin>", line 1 def random_product(*args, repeat=1): ...


3

The first thing you want to do is check how projects accept submissions and in what format (e.g. where to branch from, do you need to rebase, style guide etc.). Make that step 0. For step 3, it depends on your workflow. Mine is to clone the repo to a folder I have specially for such projects, create a virtualenv (usually using virtualenvwrapper, as it makes ...


2

The right hand side of an assignment is evaluated first. Then, if there are multiple targets, then the right-hand side should be a sequence and each element of that result is assigned from left-to-right to the targets. This means that you first get a tuple with: ((u1 - q * v1), (u2 - q * v2), (u3 - q * v3), v1, v2, v3) and then the results of that ...


2

The pipes module is pretty old. Most standard library modules that have been introduced in the last decade or so state when they were introduced on the module documentation page. For example, the sysconfig module was introduced in version 2.7. Shameless plug: I have written a script called pyqver (on Github) that attempts to identify the minimum version of ...


2

Your problem has striking parallels to functional programming: Monads, Functors, and composing functions. Your composability requirements essentially states that each operation must be a function that takes a stream and returns a stream: operation : Stream -> Stream Most functions will not be expressed in terms of whole streams but rather single frames ...


1

You asked: Can I just put the usual GPL headers on my source files, include the GPL in COPYING and leave it at that? Yes, that's fine. Or do I have to collect together all the licences and source code (both python and, e.g. C/C++ dependencies) for everything that I import and include these in my distribution? No, because they won't be released as ...


1

You tagged this with object-oriented, so the answer is: no. The fact that objects only know about their own private implementation / representation and not about that of other objects even of the same type is the defining characteristic of object-oriented data abstraction as opposed to Abstract Data Types, where instances of an ADT do know about the private ...


1

It is notably an implementation issue, not a language one (however the typing is different in the languages). Pedantically, both Python & C++ are Turing-complete languages with a lot of bindings to external libraries, so every program you could write in Python could be rewritten in C++ and vice versa. On Linux, /usr/bin/python (a.k.a. cpython) is a ...


1

You should probably use inheritance in this case, but wrapping the object you with to extend is fine as well. In fact, the technique is useful enough to have a name: the Decorator Pattern. The usual way to forward all calls in Python is not to mess around with __dict__, but to override __getattr__ ("explicit is better than implicit"): class A(object): ...


1

You can say that when we're talking about Python as a whole; including compiler that creates byte code and a virtual machine that interprets the byte code. Python as an language has no saying about if it's an compiled or interpreted programming language, only the implementation of it. Often with semantic issues, there are programming languages where the user ...


1

There is no clear distinction anymore between compiled and interpreted languages any more, as there are very few languages left that are purely interpreted. It seems like that the term 'interpreted language' is actually being used for scripting languages, where you can work in a tight "modify - execute" cycle without an explicit compilation step in the ...


1

Since you know which file is changed but not by which process this is hard but solvable. You can use psutil to handle this. With psutil you can iterate over all running processes and ask them for their open files. Written as pseudo code: for process in psutil open processes: for file in process all open files: check if this your file: ...



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