Tag Info

New answers tagged

1

You seem to have an appreciation of the trade-offs involved here. As you say, since you know all the information about your classes in advance, it doesn't quite make sense to generate them dynamically. One alternative to reduce your boring duplicated boilerplate code is to use Python's wonderful support for metaprogramming. If all your refresh methods ...


0

Interoperability is usually achieved by transferring data Generally, you can think each language being it's own separate program. This is not always the case though... Some examples: Sending sql queries to a database using json_encode() in php to encode a data structure into it's string representation, which then can be decoded by java script. Exposing ...


1

Bill Door gave some good examples where the "main program" is written in C or C++, and a scripting language is included for customization, But there is also a common, but different scenario, where the "main program", written in some "scripting language" (whatever people have in mind when they use that word) is extended by modules written in C or C++. For ...


4

In many cases, when you see multiple languages used together, you will find that one is a compiled language and the other is a scripting language. The compiled language is typically C/C++, but can be many other languages (Haskell, Erlang, Java, etc). The compiled language provides the base application. The base provides an interface to the underlying ...


0

text is a variable that will hold the content of test.txt file. You can use text variable to access the content.


5

I think you are taking on unwarranted personal risk here. It's clear from your question you already realize a larger development team is necessary, that you cannot continue to do the work of multiple people without making untenable compromises to the quality of your work, the quality of your life or both. As a software engineer, it will be up to you to ...


3

I would say Baz has broken the rules. By using self as hashable before even invoking other __init__ methods in the MRO, it assumes that those methods do nothing to influence the hash. That is a wrong assumption. Although technically it is safer to construct immutable classes so that __new__ sets up all state and makes it completely, utterly, immutable (like ...


1

The instance should be immutable at the moment it is used as a key in a dict. Before that, it can mutate. But preferably it should be incapable of mutation after the moment of construction, just to avoid programming errors. The builder pattern fits this well: the final .build() step returns an immutable object. You can additionally prevent inadvertent ...


1

Another reason is that the JVM is highly optimized, well-evolved, and extremely complete ecosystem. On it's own, it competes extremely well with any of the other compiled languages. (I won't say that it's the best general purpose VM out there, but I've certainly banked my career on that.) So getting access to the JVM, short of writing bytecode, is desirable ...


4

The earlier answers are all very good, but there is actually a language now that compiles to Python. From the GitHub project page: Mochi is a dynamically typed programming language for functional programming and actor-style programming. Its interpreter is written in Python3. The interpreter translates a program written in Mochi to Python3's AST / ...


0

The GPL primarily puts obligations on persons redistributing your code. You can't sue yourself for breaching the GPL anyway, so what you do with your own code is your own decision. Now, whether you need to redistribute source code for those libraries depends on their licenses, not yours. You may be able to rely on subsection 6c in case they use (L)GPL 3: ...


-3

It is a bit naive to ask for legal advice on Internet forums. This is a matter of law, if you are really concerned get a lawyer (I'm not one and this is not legal advice). The GPL is often more restrictive than other common licences like MIT and BSD. If it is a non-commercial application then I would not bother checking every single library for the their ...


2

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


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


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


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


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

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


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


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


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


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


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


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


0

My best tips for interviews is to (1) have some stories ready about times when you accomplished something quite well; (2) emphasize what you can do for them rather than explaining your attributes, and (3) keep your answers short, but more than a sentence. My favorite interview article source is Ramit Sethi: ...


0

Forget call-by-whathaveyou for Python Pythons scoping and parameter passing are quite simple if you do not try to understand them by these semi-well-defined call-by-X terms. A formal parameter (of a function) is a name. What you pass as the argument to the function represents an object. In the body of the function, that object will be bound to that name ...


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


0

The semantics of passing and assigning are exactly the same in Python as in Java. Java is described on StackExchange and elsewhere on the Internet (as well as by you in your question) as pass-by-value ony, and these terms must be used consistently across languages to be meaningful; therefore, Python is pass-by-value only.


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


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


0

With python, you can enter a line of code into python and expect it to be interpreted and executed immediately. Compiled languages like c, java, etc. require a compilation step which render an object that may be executable. There may be additional steps require to make the code executable. Unlike an compiled language, an interpreted language can run a ...


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


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.


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


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



Top 50 recent answers are included