Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008.

Python 3 is the latest version of the Python programming language, released on December 3rd, 2008. It features simplifications and improvements to the syntax of the language and therefore has its own tag.

Although Python 3 itself is ready for primetime and stable use, many of the popular external libraries have not yet been ported.

You should see the article Python 2 or Python 3 on the Python website before choosing which version to use.

For information on Python in general, visit the main Python tag wiki.

150 questions
172
votes
23 answers

Programming cleanly when writing scientific code

I don't really write large projects. I'm not maintaining a huge database or dealing with millions of lines of code. My code is primarily "scripting" type stuff - things to test mathematical functions, or to simulate something - "scientific…
Auden Young
  • 1,637
  • 3
  • 11
  • 21
85
votes
7 answers

How bad of an idea is it to use Python files as configuration files?

I've always used JSON files for configuration of my applications. I started using them from when I coded a lot of Java, and now I'm working mainly on server-side and data science Python development and am not sure if JSON is the right way to go any…
54
votes
5 answers

Are Python mixins an anti-pattern?

I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If I have classes like class related_methods(): …
cat
  • 734
  • 1
  • 7
  • 15
47
votes
2 answers

Why do some languages round to the nearest EVEN integer?

Programming languages like Scheme (R5RS) and Python (see this Question) round towards the nearest even integer when value is exactly between the surrounding integers. What is the reasoning behind this? Is there a mathematical idea that makes…
Profpatsch
  • 969
  • 8
  • 13
43
votes
3 answers

Why doesn't Python have a "flatten" function for lists?

Erlang and Ruby both come with functions for flattening arrays. It seems like such a simple and useful tool to add to a language. One could do this: >>> mess = [[1, [2]], 3, [[[4, 5]], 6]] >>> mess.flatten() [1, 2, 3, 4, 5, 6] Or even: >>> import…
Hubro
  • 676
  • 1
  • 7
  • 13
24
votes
8 answers

Is using lambdas to express intent not pythonic?

PEP 8 states the following about using anonymous functions (lambdas) Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier: # Correct: def f(x): return 2*x # Wrong: f = lambda x:…
N3buchadnezzar
  • 351
  • 2
  • 5
21
votes
6 answers

Does subclassing int to forbid negative integers break Liskov Substitution Principle?

In Python 3, I subclassed int to forbid the creation of negative integers: class PositiveInteger(int): def __new__(cls, value): if value <= 0: raise ValueError("value should be positive") return int.__new__(cls,…
20
votes
2 answers

How should I name functions that return values in Python?

I'm confused about choosing names for my functions in Python. Sometimes Python built-in functions are imperative such as: print function and string method find. Sometimes they aren't such as: len its name isn't imperative such as calculate_len, for…
18
votes
1 answer

What are the problems python 3 new features solve?

Python 3 new features say: we’re mostly fixing well-known annoyances and warts, and removing a lot of old cruft It mentions what is different (the fix) but not why (the problems). I have have not found what were the problems. What were the…
user712092
  • 1,412
  • 10
  • 18
16
votes
5 answers

Is using nested function calls a bad thing?

In a recent homework assignment I ended up calling my functions in an ugly way uglyReceipt(cashParser(cashInput())) the program itself worked perfectly but I still felt like I was doing something wrong. Is calling functions like this bad practice…
Carl Groth
  • 181
  • 1
  • 1
  • 4
13
votes
3 answers

Why hasn't Python been optimized like modern Javascript implementations?

Modern Javascript implementations like V8 (Chrome), SpiderMonkey (Firefox), and Chakra (IE/Edge) all have JIT compilation, and a number of other optimizations to improve performance. Why doesn't Python have these? I have been looking at PyPy and…
Jay
  • 141
  • 1
  • 4
12
votes
6 answers

Is it reasonable to use dictionaries instead of arguments?

In python I often see functions with a lot of arguments. For example: def translate(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p): // some code return(x, y, z) I like this pattern in some cases. I think it makes a ton of sense in library…
P. Hopkinson
  • 239
  • 2
  • 5
11
votes
2 answers

Using NotImplementedError instead of abstract classes

MyBase is forcing implementation of method f() in all children. This can be achieved either by using abc.ABCMeta to make f() an abstractmethod: import abc class MyBase(metaclass=abc.ABCMeta): @abc.abstractmethod def f(self, x): …
user
  • 449
  • 1
  • 5
  • 20
8
votes
1 answer

Why are variables in Python different from other programming languages'?

According to what I know, a variable in Python is a name that refers to a value stored in the computer memory, like a label on a box. but in other programming languages a variable is a location, in memory, where values are stored, and it's like a…
7
votes
1 answer

API design: stream objects vs. functions vs. messages

I'm designing API for a python library that accepts asynchronous input and produces the asynchronous output: various signals come in, and various signals are generated in response (there's no one-to-one relationship between input and output…
max
  • 1,075
  • 11
  • 19
1
2 3
9 10