Questions tagged [python]

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x.

Filter by
Sorted by
Tagged with
3
votes
1answer
331 views

Tips for Python build scripts?

File manipulation code, I've noticed, has two salient properties: It's everywhere, and vitally important to functional software It has lots of exceptions. Please give me some pointers on ...
6
votes
2answers
2k views

Slow web-scraping geolocator

How do I make my Python program faster? I have 3 suspects right now for it being so slow: Maybe my computer is just slow Maybe my Internet is too slow (sometimes my program has to download the html ...
4
votes
3answers
2k views

Menu system and Turtle

I had to do a small application using a menu system and Turtle. I have finished it and worked perfect. Just to make sure, can you please check it if it has done properly? ...
6
votes
4answers
22k views

Searching for a value from one CSV file in another CSV file

I am writing a script that takes one CSV file searches for a value in another CSV file then writes an output depending on the result it finds. I have been using Python's CSV Distreader and writer. I ...
3
votes
1answer
2k views

Python RESTful image handler

This is a view as part of a RESTful image handler module, written for Flask, I am sure there is a better/more pythonic way of doing parts of this, maybe using List Comprehensions or Generator ...
4
votes
3answers
3k views

Improving many for loops, any more efficient alternative?

I'm working through an introduction to computer science book, this is not homework for me but me trying to learn in my spare time, I'm not asking for homework help! The output is below, and this is ...
5
votes
2answers
12k views

Parsing XML in Python

The aim of this code is to return an object which contains all of the movies. Where attributes are not found, they need to return None rather than be undefined and ...
1
vote
1answer
288 views

Shorter way to write list-as-dict-value in Python?

I have a data structure that looks like this: a = { 'red': ['yellow', 'green', 'purple'], 'orange': ['fuschia'] } This is the code I write to add ...
2
votes
1answer
266 views

threading objects and urlrequests

The code below is a good representation of my coding skills. I've been at it for about 6 months. What I am interested in is ways to make the following program faster. I currently have the ...
7
votes
2answers
3k views

What is better? For-loops or generator expressions (in cases like this)

Which version of this code is better? Ver 1. a = 0 for i in xrange( 1000 ): if i % 3 == 0 or i % 5 == 0: a += i print a Ver 2. ...
11
votes
4answers
758 views

Markdown static blogger program

I was hoping I might get some of the brains in Stack Overflow to take a look at my Python static blogger application. I've been using it a few years in a pretty hacked up form. Lately I decided to ...
6
votes
3answers
699 views

Optimizing word counter

I took the Python class at Google code today, and this is what I made for the problem about building a word counter. Please take a look and suggest any improvements that can be done. Please do point ...
3
votes
3answers
268 views

Thinking in python

Magnus Lie Hetland in his Beginning python wrote a code to replicate the range() built-in. ...
2
votes
2answers
207 views

HNews “ask section” page scraping Python script

Here is a small script I wrote to get the HNews ask section and display them without using a web browser. I'm just looking for feedback on how to improve my style/coding logic/overall code. ...
4
votes
1answer
2k views

implementing simple stream processor with sockets

I'm trying to implement simple data streamer in Python with sockets. Consider one server and one or more clients. I just want to read data from server, process it and send it to the client. Here's how ...
0
votes
1answer
414 views

Recording timeback seconds of video based on compared pixels from an image

The code reads from the screen, compares a pixel in a previously provided sample image and, if the pixels match, it records timeback seconds of video leading up to it. The output is put into a folder '...
3
votes
2answers
1k views

Python prime number generator

I'm trying to get a better grasp on generators in Python because I don't use them enough (I think generators are cool). To do so I wrote a generator for prime numbers: ...
2
votes
2answers
12k views

Blackjack casino game

Blackjack (twenty-one) is a casino game played with cards. The goal of the game to draw cards that total as close to 21 points as possible without going over. All face cards count as 10 points, ...
4
votes
1answer
702 views

MP3 player for Linux

I wrote a Python MP3 player for Linux using PyGame, with a curses GUI and a mouse-only interface. It's purely for personal use. It hasn't been polished yet, but for now I'd like to know what I've ...
62
votes
2answers
81k views

Redirecting subprocesses' output (stdout and stderr) to the logging module

I'm working on a Python script and I was searching for a method to redirect stdout and stderr of a subprocess to the logging ...
3
votes
2answers
3k views

Simplifying working Caesar cipher

I'm learning Python 3 at the moment, so to test the skills I've learned, I am trying the puzzles at Python Challenge. I've created some code to solve the 2nd puzzle here. it works, but I think that ...
3
votes
4answers
2k views

Sieve of Eratosthenes: making it quicker

I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
2
votes
1answer
773 views

Finding the first and last IP in an IP range string

I'm very new to python and scripting in general. I've come up with the following function to find the first and last IP when an IP range string is inputted. I want to only use base Python (and not ...
7
votes
2answers
227 views

Command line tool for Italian language studies

I made a small command line tool to help my Italian studies. Any thoughts on how it could be improved? I can't think of much but would like to be proved wrong. ...
9
votes
2answers
2k views

Pangrams CodeEval challenge

I took a challenge on CodeEval. Although the code seems to work for the examples taken from the site, I feel it is not really pretty and must be more complicated than it should be. Description: ...
5
votes
1answer
2k views

How can I optimize this Monte Carlo simulation running at 10,000,000 iterations?

I am writing this Monte Carlo simulation and I am facing this issue when running the code at 10,000,000 iterations. here is the code: ...
3
votes
1answer
2k views

Python simple int subclass

The below is a class designed to implement Rememember the Milk's task priorities. I'm using it partly as an exercise in "Pythonic" programming, so it's fairly simple already, but advice on how to make ...
4
votes
1answer
469 views

Back propagation neural network

This is the first time I tried to write a back propagation ANN and I would like to know what more experienced people think of it. The code is meant to distinguish if text is written in English, French ...
14
votes
4answers
18k views

Comparison to infinity when checking if a point is above a line

I have a function that is being called in a tight loop. I've profiled my code and this is where my largest bottleneck is. The function is fairly simple: it checks if a point in (x,y) form is above a ...
4
votes
1answer
2k views

Automatically backup website files and database

For each of my various websites, I back up the web site files and the associated database for into a single dated compressed archive file (one zip file per website) and download that to my local ...
2
votes
1answer
365 views

Running a given command after each change in a file

I would love to hear some comments on this small script, which (I hope) reduces repetitive tasks such as page refreshing, compilation and so on to minimum. ...
1
vote
1answer
241 views

Excessive use of lambda with variant of Sieve of Eratosthenes?

This is a function which produces the sum of primes beneath (not including) a certain number (using a variant on the sieve of Eratosthenes). ...
2
votes
1answer
3k views

Simple interactive backup script

How can I improve this? GitHub ...
6
votes
1answer
416 views

Regexes for Google App Engine

I want to review the URL routing for my appengine webapp: ...
3
votes
1answer
4k views

Reading a large XML file and parsing necessary elements into MySQLdb

I have fair concept in a programming (learner) but not an expert to refactor code at the highest level. I am trying to read a huge (100MB-2GB) XML file and parse necessary element (attributes) from a ...
3
votes
1answer
828 views

i18n translator using Jinja2

I'm learning to Jinja2 and what's important in this case isn't speed but i18n translations and functionality. With Python 2.7, Jinja2 and not Django seems to preferred way to go, so I'm rewriting much ...
3
votes
1answer
695 views

Bencode “Parser” in Python 3

class BencodeObject: ...
6
votes
1answer
294 views

How to improve my auto-reconnection Python script

I need some feedback here. Due to a weird issue on my server system, the network card disconnects from the network regularly. I'll fix this at a later date. But I wanted to know if the below script ...
0
votes
1answer
79 views

How to optimize the code to save data at GAE datastore?

I have the following code (for Country and City classes key_name is numeric id with addition ...
2
votes
1answer
373 views

HTML editor for Google App Engine

Please review this simple code. When I review it I decide to rewrite so that it doesn't write to a template, but instead directly to output since the whole HTML is fetched from the data layer. I used ...
1
vote
1answer
191 views

Is this a “pythonic” method of executing functions based on the values of a tuple? [closed]

I have a situation where I have six possible situations which can relate to four different results. Instead of using an extended if/else statement, I was wondering if it would be more pythonic to use ...
10
votes
3answers
293 views

Reorder list such that each element is followed by the value closest to it

I just started playing with Python and was hoping to get some feedback regarding the quality of the following snippet. Does this look like proper Python? What would you change? Is this small script ...
3
votes
2answers
2k views

Improving and optimizing Tic-Tac-Toe game written in Python 3

I've been teaching myself Python3 for about a week now and I decided to put my skills to the test by writing a simple Tic-Tac-Toe game. Here is what I came up with: ...
1
vote
1answer
164 views

Does this function cache correctly? [closed]

I want to limit the load so I rewrite the most expensive method and add caching, both memcache and cache-control: ...
2
votes
1answer
859 views

Converting an object into a JSON string

I wrote a Python method to convert an object and a subset of its attributes into a JSON string with a given field as the key. There's a lot of string concatenation, and I'm not too sure what the best ...
1
vote
1answer
204 views
1
vote
1answer
144 views

Grouping consecutive numbers into ranges in Python 3.2 : New version for set

...
5
votes
2answers
759 views

How can I improve my A* algorithm in Python?

I'm trying to implement my own A* pathfinder, but the voices in my head scream of better ways to do this. Probably because I'm exceeding Python's default maximum recursion depth of 1000. ...
3
votes
1answer
2k views

All tangled up in IF and ELIF and TRY

I'm working on a small program to add or remove certain entries from the Windows registry, and I'm getting all tangled up in IF and TRY conditions. I've spent hours chasing bugs, usually logical ones, ...
13
votes
5answers
20k views

Grouping consecutive numbers into ranges in Python 3.2

The following is a function that I wrote to display page numbers as they appear in books. If you enter the list [1,2,3,6,7,10], for example, it would return: <...