All Questions
Tagged with python python-3.x
98 questions
174
votes
23
answers
26k
views
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 ...
93
votes
7
answers
28k
views
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 ...
54
votes
5
answers
40k
views
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 ...
43
votes
3
answers
82k
views
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]]
&...
24
votes
8
answers
7k
views
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: ...
21
votes
6
answers
6k
views
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 ...
20
votes
2
answers
16k
views
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 ...
18
votes
1
answer
1k
views
What are the problems python 3 new features solve? [closed]
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 ...
15
votes
5
answers
19k
views
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 ...
15
votes
2
answers
15k
views
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):
@...
13
votes
6
answers
11k
views
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 ...
9
votes
1
answer
9k
views
Why are variables in Python different from other programming languages'? [closed]
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 ...
7
votes
2
answers
10k
views
How many types of polymorphism are there in the Python language?
I just read an article by Luca Cardelli and he explained types of polymorphism which are:
The article is named On Understanding Types, Data Abstraction, and Polymorphism.
Types of Polymorphism
...
7
votes
1
answer
455
views
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-...
5
votes
2
answers
2k
views
Does this code follow duck typing?
The principle of duck typing says that you shouldn't care what type of object you have - just whether or not you can do the required action with your object. For this reason the isinstance keyword is ...