Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. ...

learn more… | top users | synonyms (1)

3
votes
3answers
204 views

Functional style exception handling

I've been told that in functional programming one is not supposed to throw and/or observe exceptions. Instead an erroneous calculation should be evaluated as a bottom value. In Python (or other ...
3
votes
1answer
80 views

Why was the warning about % formatting toned down in newer Python docs?

The Python 3.1.5 docs refer to the % style formatting as "Old String Formatting Operations" and provide this warning that it may be removed: Note: The formatting operations described here are ...
4
votes
3answers
145 views

How to DRY with calls to a database to execute?

I'm writing a python app that instructs a database to perform various processing instructions on partitioned tables. The processing can take long enough that there might be a timeout, so I surround my ...
-1
votes
0answers
16 views

reading and slicing a 2d list in python [migrated]

There is a file, just like this, called: test.txt: John,19,7.5 Mary,22,9.8 Daniel,45,7.2 Hubert,92,10.0 Guy,28,9.5 I'm gonna extract the columns 2 to 4: grades = np.genfromtxt(r'\test\test.txt', ...
8
votes
4answers
191 views

Class decorators in Python: practical use cases

I am looking for practical and non-synthetic use cases of Python class decorators. So far, the only case which made sense to me is registering a class in a publisher-subscriber system, e.g. plugins or ...
3
votes
2answers
127 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 ...
4
votes
3answers
254 views

Is it reasonable to write worse debug code in order to improve production code?

The title pretty much speaks for itself, but I'll provide the current decision I am facing. I am migrating python code towards the use of generators. The current code looks like this: ... l = ...
2
votes
1answer
62 views

Where do you put the “main function” of a Python app?

Suppose you are developing a Python standalone application (not a library). Would you make it a Python package? Or just files next to each other? If you would make it a package, what would be the "...
0
votes
1answer
57 views

Using singletons in Python (Django)

I was suggested to define a singleton in Python in the following way: class Controller: pass # ... controller = Controller() However, this way, controller cannot be replaced with a derived ...
0
votes
1answer
58 views

Error checking design question (python & MVC)

Which is better as a design perspective? An object that gets initialized and then checks to see if the parameters passed to it are valid before destroying itself (so in __init__) or Check to see if ...
1
vote
1answer
52 views

suggestions on pygame code structuring?

so I made a simple game where boxes fall from the top of the screen and you have the dodge them from the bottom of the screen. When a box falls to the bottom of the screen without hitting you get a ...
-3
votes
0answers
96 views

Why not rewrite CPython?

Python is a very popular programming language and CPython is the most common implementation (to the point where when we say "Python" we usually mean CPython). However CPython has its "problems", most ...
0
votes
0answers
22 views

LALR parsing (with Ply) non-deterministic and sometimes fails

I have written a parser using Python Ply library. While doing tests with an input file I have noticed a strange behaviour : sometimes the input is correctly parsed with no error and sometimes, there ...
0
votes
2answers
61 views

Using a class for a collection element, with methods to access other collections

I'm hoping for a sanity check in my design thinking. I'm working with a small team on a website based on a MongoDB database. There are several collections in the DB -- for example, one representing ...
0
votes
0answers
21 views

Effective method for using both modified and original open-source Python module

I'm wondering if anyone has come up with an effective method to work on and use a modified version of an open-source Python module, while still using the unmodified one. (For example, to compare old ...
-1
votes
0answers
31 views

Automatically adding an admin user to Python program

I am not sure if this is the correct place to ask, I normally use stack-overflow but as there is no code in the questions I feel this is better suited here. I am developing a python app which uses ...
0
votes
1answer
29 views

Memory override using classes when using lists in python

I am trying to create a new variable with class Lamb (called hold) using a variable (main), which also has class Lamb. Lamb has two parameters (x and y). I create a variable called main with class ...
5
votes
3answers
270 views

Does Python's defaultdict violate the LSP?

I believe, in Python defaultdict inherited from dict violates Liskov Substitution Principle. defaultdict doesn't raise KeyError while x in d is still False, for instance. Is that so? If it is, why ...
2
votes
3answers
127 views

How to mock REST services for testing

I am currently building an application that consists of multiple small rest services that communicate between them. For example, a request to service A might make requests to services B and C in the ...
3
votes
4answers
183 views

Why raise an exception if python raises it for me?

I have a global position keeper of screen items so items don't need store their own positions. class Screen_Position_Keeper: # functions to add stuff def get_px_row( self, item ): ...
0
votes
0answers
37 views

Two processes in a single docker container or two services connecting to the same db?

I recently started moving a monolithic application to microservices architecture using docker containers. The general idea of the app is: scraping data -> format the data -> save the data to MySQL -...
0
votes
0answers
39 views

How does the FOSS exception for MySQL connectors apply to code written in PHP or Python?

I have looked all over and can't find clear answers to the following: If I write code in PHP or Python that uses GPL MySQL connectors for PHP or Python - which license applies to my code? That of PHP ...
0
votes
2answers
84 views

Creating instances of an ability when there are multiple different type of abilities

I'm creating an RPG game where a player has a set of skills, each of which he can level up to improve its effect. Here are two example skills: health: increase player's maximum health regeneration: ...
-2
votes
1answer
68 views

How to explain this method to find the least common multiple of the first n natural numbers?

This is the Project Euler question #5. The statement is pretty much finding the least common multiple of the first n natural numbers. So for example, the least common multiple of 1, 2 .. 10 is 2520. ...
-2
votes
1answer
62 views

How to ask a user how many inputs they want

I want to know if it possible to use arrays for a more viable alternative of getting a non-predetermined number of inputs as an array and with an indefinite number of inputs. (python) original code --...
-1
votes
1answer
67 views

Can I use python 3.5.2 on my machine for development if the client is 3.4?

Here is the situation, I wish to use the last programming language of ruby, python and some more on my development machine, but the server where it will be is not last version of that programming ...
3
votes
2answers
116 views

How to decouple UI from logic on Pyqt/Qt apps properly?

I've read quite a lot about this subject in the past and watched some interesting talks like this one from Uncle Bob's. Still I always find pretty difficult to architect properly my desktop ...
3
votes
3answers
142 views

Stateful vs stateless (non web app) applications

I would like to understand the difference between stateful and stateless applications. What would be a non web app example of a python application which is stateless vs stateful? Would a script which ...
-3
votes
2answers
51 views

Python function (or set of functions) as input of a function or class

is there a way of having an (yet unkown) function as an argument of a function in python: def doSomething(<func>): #do something with func() at a later stage, functions could be defined, ...
2
votes
2answers
111 views

Function acting as a shortcut to object's methods

I was reading Python's requests library's code to find out how it works. Since this library has a simple usage interface, it creates a more complex object beyond. For instance: requests.get(...) Is ...
0
votes
1answer
204 views

Can I use Python with JavaScript as a UI?

First of all I am not a professional programmer, but a student with a programming hobby so I am sorry if my question is stupid. I want to write a chess engine to be used on the web and had already ...
0
votes
0answers
14 views

How to protect quickly-incrementing variables in Django?

I want to count how many times an image is loaded on a webpage. We are looking at maybe 100 times per second. One option is to store every impression as a row in a database, but this would get ...
1
vote
4answers
197 views

Why does string.find(“”) = 0? [closed]

I'm studying Python and hung up on a simple problem. Let's say we have: string = "hello" When we invoke the find method on the string to find an empty string like this: string.find("") Why does ...
-3
votes
1answer
89 views

Python recursion in functions [closed]

I am just learning about recursive functions. This was an example given in a textbook where t is a turtle. I was wondering how the code works, but more specifically, how the code runs past the first ...
0
votes
0answers
24 views

caveats while using one server as staging site for many projects?

EDIT: I realize this sounds like I am describing a development server, but I am actually hoping to test the project(s) on a node that is "as close to production" as possible. Contrast this with my ...
1
vote
3answers
127 views

Handle backward compatibility on API changes

I have an API which allows me to communication with a device. The communication protocol is stored in a JSON file. It list the events that the device can raise, the functions, the frames format, etc. ...
0
votes
1answer
45 views

Can software under the “BSD 2-Clause License” be uploaded to PyPI?

Note: I'm not that experienced in working with licenses, so this could be a quite ignorant question. I've also read this other article on programmers.stackexchange before asking this question. I've a ...
2
votes
2answers
129 views

Approach for refactoring a function that has lots of special braching

I am writing a function that operates slightly different depending on the data passed in. The common and unique code is mingled. I don't like what I have and am looking for a better way. Hopefully, ...
3
votes
1answer
203 views

Python-style Keyword Args in C++ - good practice or bad idea?

While trying to figure out the optimal ordering for optional parameters to a function recently, I stumbled across this blog post and accompanying GitHub repo, which provides a header for a Pythonic ...
1
vote
1answer
133 views

Can I really make python work with VBA

I'm a heavy VBA user that when has the chance to do a little project in python it's like going from hell to haven when it comes to programming itself. Still, I know that my users want reports in excel ...
2
votes
2answers
82 views

Setting class/methods conditionally

I want to keep the end-user (often myself) from being presented with inapplicable methods when coding directly in an interpreter, but I also don't want the user to have to inspect the incoming data ...
0
votes
1answer
75 views

How can I create a set of pixel coordinates for a line in Python?

I've got some code that's searching pixel by pixel from a starting point, at a certain angle, until it finds a pixel (a non-white pixel) It only has to search around 300 pixels: I'm currently using ...
-1
votes
1answer
265 views

Can an OS be created with Python?

I have been pondering over the idea of a Python-based Operating System on top of the Linux kernel, much like how Android uses Java. What if most of the system components were built using Python, this ...
2
votes
2answers
113 views

Unknown number of arguments in currying

Hypothetical situation - can a currying function have an unknown number of arguments (kind of like varargs) Eg in Python: addByCurrying(1)(2)(3)(4) Should equal 10 addByCurrying(5)(6) Should ...
0
votes
0answers
23 views

Proper position to insert extra field/subfield

Background I am working with JSON data.I have defined a fixed schema for my db table customer: "name":["fname":"string","lname":"string"],"location":"string" Now my json data is dynamic,certain ...
-4
votes
1answer
55 views

Python - units for a slope calculation

Simple question: is the result of a slope calculation in Python (say, stats.linregress() function) in units of radians, or unitless (e.g. what's 18 deg or 0.314 rad would be equivalent to 0.2 in the ...
-1
votes
1answer
77 views

Why do we use 'assert not' in this example?

My code takes 2 dates and finds the age of those dates in days. In my daysBetweenDates method the instructor uses an assert statement: assert not dateIsBefore(year2, month2, day2, year1, month1, day1)...
0
votes
0answers
26 views

Python - getting record count from a streaming socket

Some context - I'm converting a function from another language (source) which has the following structure: CompoundValue(int length, IDataHolder visible data, IDataHolder historical data) an example ...
0
votes
2answers
70 views

How to name variables that clash with functions?

As an example, in Python I have a lowest_prime_factor function which does it exactly what it says it does. Then, in another function, I need to call this function and store it. In another language ...
-1
votes
2answers
62 views

Variable can't hold str() method information with “pure” word in brackets… why?

I've recently bumped into string methods and mainly str() method caught my interest because, it makes string out of every type of data? integers, booleans and so on. And if you want, they can be ...