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

learn more… | top users | synonyms

2
votes
0answers
23 views

Accelerate OpenGL 2d on python3

I used OpenGL to draw about 20 circles. Each circle has 2 lines, ~10 segments, and all of them have different colors and lenght. FPS ~=4. How can I do this faster? I am using Python 3 on Ubuntu Sorry ...
0
votes
1answer
54 views

Twitter Filter Code Review

I submitted a previous version of this program but I've completely rewritten it in an Object Oriented style. This is only my second attempt at OO programming so I'm interested in hearing how I can ...
2
votes
1answer
97 views

What steps to turn python code into python zen code

My python code is ugly and I'm having difficulty improving it. What kind of steps could be done here to make it. This is an example function that comes from time to time and I can't seem to have a ...
2
votes
2answers
46 views

Wrapping an Exception with context-management, using the with statement

Before I try to make this work, I wondered if anyone had tried this, whether it was a good idea or not, etc. I find myself doing this a lot: if some_result is None: try: raise ...
5
votes
2answers
152 views

Help refactoring my tic tac toe game

I'm very new to coding and have been diving into the skill with Python as my first language. One of the first programs I wrote for a class was this Tic Tac Toe game. I re-wrote this game using classes ...
1
vote
1answer
51 views

Python script to update a cPanel zone record with my public IP

This is my first attempt at using Python to send http requests. I want to keep a zone record on cPanel pointed at my home network's public IP. I'm just looking for some general feedback/suggestions. ...
2
votes
1answer
28 views

Eliminate for loops in numpy implementation

I have the following dataset in numpy indices | real data (X) |targets (y) | | 0 0 | 43.25 665.32 ... |2.4 } 1st block 0 0 | 11.234 |-4.5 } 0 ...
0
votes
1answer
44 views

Is it worthy to create a wrapper function like this?

I have a few Python codes like this: workflow = [] conf = {} result = [] prepare_A(workflow, conf) prepare_B(workflow, conf) prepare_C(workflow, conf) result.append(prepare_D_result(workflow, ...
1
vote
2answers
65 views

Looking for Python code review of database abstraction class

I'd be very thankful if some Python masters would take a look over the following class and review the code. There is no bug(not as far as I know anyway), the code is working as intended. But, since ...
1
vote
1answer
117 views

Inserting data into database by Python

I have to run a python script that enters data into MySQL database table. My below query runs and inserts data into MySQL database. But I want to optimize it and I have 2 requests: I want to use ...
5
votes
2answers
121 views

Critiques on a trivially easy to use Python CSV class

I have been working on a project where I needed to analyze multiple, large datasets contained inside many CSV files at the same time. I am not a programmer but an engineer so I did a lot of searching ...
2
votes
0answers
30 views

How to improve performace of this Map Reduce function, Python mrjob

I'm trying to get the most out of this code, so I would understand what should I look for in the future. The code below, works fine, I just want to make it more efficient. Any suggestions? from ...
2
votes
4answers
82 views

Tic Tac Toe-Check Victory

I am writing a python code for making a tic tac toe game. I need to write a function that takes in three inputs, board, x, and y. Board being the current display of the board and then x and y being ...
2
votes
1answer
74 views

faster Django csv generation on the fly

I am writing a csv file generator that's filtering through about seven million db entries. {mySQL backend} This part is especially slow and I was wondering if there is a way to make it much faster. I ...
0
votes
2answers
51 views

Possible Bugs in substring program

I have written a small snippet to validate a substring in a string in O(n). I have tested the code using some combinations. I require your help to let me know if there are any bugs in my code with ...
1
vote
1answer
41 views

Python simple function - evaluating arguments

Think of the numpad number layout. hvd = horizontal, vertical or diagonal coord = 1,2 or 3 if horizontal or vertical and 1 or 2 if diagonal (1 is up, 2 is down)... hello('v', 2) - Asking for the ...
1
vote
1answer
50 views

Using numpy polynomial module - is there a better way?

I'm working on a project where I need to solve for one of the roots of a quartic polymonial many, many times. Is there a better, i.e., faster way to do this? Should I write my own C-library? The ...
3
votes
1answer
97 views

Is this a secure way to hash a password

I'm implementing a login system on app engine (I have to, so please don't tell me to use the User service, or an other way to delegate authentication), and I'm wondering wether this setup is secure. ...
6
votes
4answers
154 views

Readability and Performance of my Trie implementation

As an interesting exercise in Python 3.3, I implemented a Trie (also known as a Prefix Tree). Example usages Create from list of key-value-tuples mapping = (('she', 1), ('sells', 5), ('sea', 10), ...
0
votes
1answer
60 views

Improvment of and looping in a regular expression pattern

My implemented regex pattern contains two repeating symbols: \d{2}\. and <p>(.*)</p>. I want to get rid of this repetition and asked myself if there is a way to loop in Python's regular ...
2
votes
2answers
100 views

Optimize BFS weighted search in python

I have a weighted BFS search in python for networkx that I want to optimize: def bfs(graph, node, attribute, max = 10000): # cProfile shows this taking up the most time. Maybe I could use heapq ...
2
votes
2answers
101 views

How can I optimize this recursive function?

I have a function that I need to optimize: def search(graph, node, maxdepth = 10, depth = 0): nodes = [] for neighbor in graph.neighbors_iter(node): if ...
1
vote
3answers
74 views

update list based on other values

Basically I have a 2d list containing movies. Movies are specified by name, version and description. For example ['Jaws', 1, 'Movie about sharks'] - where Jaws = name, 1 = version and Movie about ...
2
votes
3answers
88 views

An attempt at a simple type safe python enum

There have been many posts here about enums in python, but none seem to be both type safe and simple. Here is my attempt at it. Please let me know if you see anything obviously wrong with it. def ...
-2
votes
2answers
152 views

Any way to change optimize this or/and change to recursion?

Number can be very big.Script is taking number as a "number" list and crossing from 10-decimal based system to n-based system until list equals "5".I don't use letters like in 16-base ...
3
votes
1answer
45 views

Finding missing items in an int list

Here is a problem I am trying to solve: trying to find missing photographs from a sequence of filenames. The problem boils down to: given an unsorted list of integers, return a sorted list of missing ...
1
vote
3answers
67 views

Updating list of Dictionaries from other such list

Basically I have created a function which takes two lists of dicts, for example: oldList = [{'a':2}, {'v':2}] newList = [{'a':4},{'c':4},{'e':5}] My aim is to check for each dictionary key in the ...
1
vote
3answers
93 views

Could I possibly shorten / clean this up

I'm new to Python, and I'm wondering how I could possibly shorten / clean this up? def userAnswer(letters): print("Can you make a word from these letters? "+str(letters)+" :") x = ...
2
votes
2answers
66 views

Python: Find and process duplicates in list of lists

I'm trying to merge counts for items (urls) in the list: [['foo',1], ['bar',3],['foo',4]] I came up with a function, it's slow when I run it with 50k entries. I'd appreciate if somebody could please ...
5
votes
1answer
80 views

Thoughts, opinions, and advice on my Alien battle code

I'm a beginner Python programmer. I've recently written a program for Python 3 that I'm using to practice my newly-acquired object-oriented knowledge. It's a simple text game that is really easy to ...
-1
votes
2answers
62 views

Unpacking sequences for functions

After watching Raymond Hettinger, I decided to go through my code and make it faster and more beautiful. The example given on the slides is, unfortunately, not good enough to get me going (ref. ...
1
vote
2answers
52 views

Given a random section of text delimited by line breaks, get the first paragraph

REQUIREMENTS: Given a long section of text, where the only indication that a paragraph has ended is a shorter line, make a guess about the first paragraph. The lines are hardwrapped, and the wrapping ...
2
votes
3answers
106 views

Python: How much logic is enough logic, and how much is too much logic in an __init__ method?

I am writing an email parser and cannot decide how much logic should be included in the __init__ function. I know, a constructor should make the object ready for use, but are there best practices to ...
2
votes
2answers
93 views

Raising an assertation error if string is not an email

I created a class EmailParser and check if a supplied string is an email or not with the help of the standard librarie's email module. If the supplied string is not an email I raise an exception. ...
1
vote
1answer
66 views

run external command from python

I have to run an external program from python. External program makes many temporary files (which conflict with other instance of same program). My strategy is Get current directory (native) path, ...
2
votes
2answers
118 views

Decorators - a more elegant solution?

What I really like about SO, is that you get to see some many different ways of doing things! I am seeing a lot of use of itertools, and I am trying to get my teeth into that module more. I also see a ...
0
votes
0answers
60 views

Bit array not working as fast as expected [closed]

I recently downloaded the bitarray module from here, for a faster prime sieve, but the results are dismal. from bitarray import bitarray from numpy import ones from timeit import timeit def ...
2
votes
0answers
41 views

Load modules conditionally Python

I'm wrote a main python module that need load a file parser to work, initially I was a only one text parser module, but I need add more parsers for different cases. parser_class1.py parser_class2.py ...
0
votes
1answer
49 views

Python Port scanning: am I doing it right?

So I am making a python program with what I learned so far where the user enters two IPs that represents the start and and of the range of IPs to be scanned than saves the wanted IP in a text file. ...
4
votes
1answer
134 views

Correct implementation of a markov-chain?

I read about how markov-chains were handy at creating text-generators and wanted to give it a try in python. I'm not sure if this is the proper way to make a markov-chain. I've left comments in ...
1
vote
1answer
80 views

GUI system in PyGame

I'm making a GUI system in Python for game development with PyGame. Right now I have a button that changes colors when you hover and click on it. My question is, is this code well designed or can it ...
2
votes
1answer
213 views

Snake game — made with Python

I wrote a simple Python snake game, it's about 250 lines of code. Can someone give me some advice on how to refactor/make it better? game.py # game.py - 3/22/2013 import pygame, sys, os from ...
2
votes
4answers
82 views

Python OO Code Review for small blogging script

I've recently re-written a Python script I use to run a couple of lightweight blogs. Looking over the horrible code I'd written before, I decided to rewrite it using object-oriented concepts. I wanted ...
2
votes
2answers
206 views

How do I make this program run less unnecessary loops?

I am currently trying to teach myself some programming. I have started to work with Python by doing this challenge. When I test run it works out fine, however when I run this code with longer strings ...
1
vote
2answers
103 views

Code review and refactoring this Python program

Here's a simple Python Flask app. It uses the wikidot API to transfer pages between two wikis. I'd like to hear your input on the best way to refactor this code. Here are a couple of questions I ...
2
votes
1answer
61 views

Iterative Collatz with memoization

I'm trying to write efficient code for calculating the chain-length of each number. For example, 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1. It took 13 iterations ...
2
votes
1answer
68 views

Python multiprocessing messaging code

I am just learning how to do some multiprocessing with Python, and I would like to create a non-blocking chat application that can add/retrieve messages to/from a database. This is my somewhat ...
1
vote
2answers
93 views

Is this class structure good?

I'm writing a pong game in Python and I created classes for the game objects. The top level class is Object, and Ball and Paddle inherit from it. And ComputerPaddle is a child class of Paddle. # ...
1
vote
1answer
115 views

Improving performance of my python code

I wrote a python program that performs a Simpson integration of data. The program takes the areas to be integrated from a foo.ref file, with the following syntax: # peak m/z ...
3
votes
1answer
158 views

My first python graph traversal review

I'm trying to solve a graph traversal problem I found, and was wondering how I could improve my implementation. Currently it seems a little convoluted and long. The problem is as follows: I have a ...

1 2 3 4 5 17