Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

2
votes
0answers
19 views

Rotating greyscale images

For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any rotate() function, but doing the math. I was wondering if it could ...
0
votes
0answers
46 views

Script to import repositories to Bitbucket

I needed a script to import repositories from other Bitbucket account to my own Bitbucket account. I have some 250 repositories in my account and I wanted them to move under Team (which is same as ...
0
votes
1answer
40 views

Naming for a variable in before and after status and different type of variable

I'm not a native English speaker, so I'm unsure about this. Is it ok to name a variable and put the prefix "before" and "after"? If not, how could I give it a better name? before_len = ...
15
votes
4answers
2k views

Is it a good practice to put exceptions in every method?

I don't know if it is a good idea to put exceptions in every method. I always put an exception when every new method is created, and I don't know if it is a good or bad practice. I thought it may be ...
6
votes
1answer
87 views

Strange performance difference

For exercise, I wrote this code: def BigPrime(numP, plist = [], x = 1, counter =0): while len(plist) <= numP: if x == 1 or x == 2 or x == 5: plist.append(x) ...
6
votes
0answers
31 views

What is the most pythonic way to solve a Differential equation using the euler method?

For example with this Differential Equation how can I do it in a pythonic way? dx/dt=f(x,t) I have a way to do it but I think this is not the most pythonic way to do it. Here is how I do it: ...
6
votes
1answer
45 views

Python compress and send

The following two functions are used to compress arbitrary Python objects and send them safely via socket or email, using only printable chars. In my specific message protocol, '=' signs are also not ...
2
votes
1answer
56 views

Run a TCP server listening for incoming messages

I've written the following code, but I need some review on design style. I want to develop a library/module and expose an API to client programs. How do I do that? The code just runs a TCP server ...
9
votes
3answers
293 views

Installing “mods” with Python

A little disclaimer: you're going to have a field day with this. It's horrible. Looking at it makes me want to vomit, and don't ask me to explain it, because I've long forgotten what I was thinking ...
3
votes
1answer
39 views

Insertion sort with binary search in Python

def binary_search(A, value, start, end): # we need to distinugish whether we should insert # before or after the left boundary. # imagine [0] is the last step of the binary search # ...
4
votes
1answer
42 views

Dice game in Python

I was wondering if this script in Python could be shortened? import random def var(): strength = 10 skill = 10 dice4 = 0 dice12 = 0 dice_score = 0 character_name = "" ...
6
votes
1answer
28 views

Script to checkout multiple repositories to a certain commit hash

I am writing a script which checkout a git repo to certain commit hash, do something and switch back to master. The purpose of this script is to take homework solutions of students from bitbucket. ...
7
votes
2answers
61 views

Long constructors, inheritance, class method constructors

My class takes functions as a parameter. There are 6 of them, along with numerous other parameters. Almost all of the fields have default values. It also has a class method that creates an instance ...
7
votes
1answer
36 views

Review implementation for Partial Ordering of Vectors

Partial ordering may be useful in some scientific contexts. This is quick prototype in Python, which I believe works correctly. Do you notice any flaws? Can you provide a counter-example of wrong ...
0
votes
0answers
21 views

Using module level declared global “singletons” in python [migrated]

Ok, I know that using singletons is generally a bad practice, but if I do it (for db connection, logging et al.) am I allowed to go (in respect of clean design) with a module defined variable that is ...

15 30 50 per page