Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.

learn more… | top users | synonyms

1
vote
0answers
13 views

Return JSON data based on GeoDjango Queryset

My code below returns a JSON data based on user's input or query in my HTML page or template. However, I need to modify or do some tweaking with my JSON data in order for me to use it in my datatables ...
3
votes
1answer
36 views

Python mnemonic <==> hex conversion (Bitcoin BIP39)

Following up from the fantastic feedback re pbkdf2 code... I'm looking for commentary on the following code, which converts from a hex seed to mnemonic (12 word phrase), and vice versa. It's for ...
4
votes
1answer
42 views

Python PBKDF2 using core modules

I'm trying to implement pbkdf2 in Python 2.7/3.4 without needing the pbkdf2 module. (I'm also trying to avoid using classes.) Any insight would be appreciated: ...
3
votes
1answer
54 views

Testing Fibonacci conjecture

The sequence of Fibonacci numbers is defined as F1 = 1, Fn = Fn−2 + Fn−1. It has been conjectured that for any Fibonacci number F, F2 + 41 is composite. ... [T]ask is to either prove the ...
-2
votes
0answers
40 views

How can you multiply faster the digits in python 2.7.8?

This is my source. Can it maybe done faster and more elegant? ...
0
votes
0answers
24 views

Files in directory change detection script [closed]

Got an internship invite as a Junior Python Developer and have a task to: Write a python script that detects changes in given type of files (*.php or *.js) in that path and reports it in a form ...
0
votes
0answers
6 views

Strip carriage returns / line feeds from database records before they are written to csv [closed]

I have the following code that reads lines from a database and writes the matching results to a csv file. The problem I am running into is there are occasionally carriage returns / line feeds in some ...
1
vote
0answers
13 views

Replacement for 'for-loops' in PyQGIS (Python 2.7.5)

I'm using Python 2.7.5 in a GIS environment (namely: QGIS 2.8.1, or PyQGIS) sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0) I wrote my first code which is attached ...
4
votes
1answer
50 views

Reading in a series of Excel files

I needed to create a program which reads in a series of Excel files in folders typically structured something like this. ...
1
vote
0answers
35 views

File transfer using yandex.ru cloud storage

I've made a "envtransfer" application transfer environment between computers using Yandex disk application. I would like to hear the opinion of the code. Big thanks. User authorize, get token, export ...
1
vote
0answers
127 views

A dictionary that allows multiple keys for one value

I'm trying to learn to program on my own with the help of books and the Internet and thought I'd start a project (a sub-project for a project). I want to build a dictionary that allows multiple keys ...
3
votes
1answer
94 views

Instantiating a kind of NumPy array

I am creating a class object which must inherit from numpy ndarrays. I perform an isinstance check and an ...
8
votes
1answer
58 views

Ring datatype in Python

I wanted to write something that would be useful for the indices of a grid where if one walked off the edge of the grid they would re enter on the opposite side. This could in theory help with ...
0
votes
0answers
22 views

Can I condense these values with a loop? [migrated]

I have a set of values that get modified like so: ...
6
votes
2answers
239 views

Project Euler Problem 12 in Python

I'm trying to do Project Euler Problem 12, which reads as: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 ...
2
votes
2answers
47 views

Bubble sort a list of integers for a number of iterations

I wrote a program for this problem, but it stopped because it took too much time. Any tips? The Problem: Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
4
votes
3answers
216 views

Stack Implementation in Python

I have written a simple stack implementation and would like some feedback as to what I could improve in my code and coding practices. ...
3
votes
1answer
35 views

OVH email manager script using docopt

This is what I coded to realize a command line program to make it easier to manage emails on ovh shared hostings. It's working ok but it seems ugly. I'm a beginner with Python and ...
2
votes
2answers
75 views

Web-scraper for a larger program

I have a web scraper that I use in a part of a larger program. However, I feel like I semi-repeat my code a lot and take up a lot of room. Is there any way I can condense this code? ...
2
votes
1answer
38 views

CSV manipulation with Python

I've prepared a script to manipulate csv files in Windows that simply adds quotes as requested. The script creates a backup of the original files and overwrite the wrong originals in its same folder. ...
2
votes
1answer
68 views

Simple sum calculator

I'm looking to optimize a simple sum calculator used in Project Euler+. The premise is simple: Find the sum of all the numbers divisible by 3 or 5 under X. At first I did it like so: ...
3
votes
1answer
57 views

Long running Python “server status” collector

I wrote a small program that collects the server status, caches it for a certain amount of seconds, and then sends that to a mothership server. It's broken down into a few pieces, starting with ...
2
votes
0answers
77 views

Multipurpose command-line utility to manage a web application

I'm creating a command-line tool which is supposed to work on both Windows and Linux OS. It will be used to manage our application - start, stop, deploy etc. We have it in bash scripts now (and it ...
4
votes
1answer
237 views

Optimizing critical loop for consuming a byte-buffer

I'm currently developing an Open Source project called sims3py using Python2.7. One overarching goal of the project is to ensure a Pure Python implementation of functions currently available only ...
1
vote
0answers
57 views

Download a file from given URL and retry on connection errors

I wrote script for Python 2.78 which is supposed to download and save a file from a given URL using the requests library. In case that a connection to the server can be established and a valid ...
4
votes
1answer
63 views

Class-based user input validation

Having contributed to this Community Wiki on StackOverflow regarding validating user input, I thought I'd finally sit down and write something more robust to do these kinds of tasks. I wanted ...
3
votes
1answer
70 views

N-puzzle program solved using A* search

I coded the following program to solve the n-puzzle problem with n = 3. Are there any suggestions regarding readability and variable names? ...
3
votes
4answers
177 views

Count the ways to partition an array into two equal sets

I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items. Suppose ...
3
votes
2answers
247 views

Reverse Polish Notation calculator in Python

After reading the definition, I made a simple Reverse Polish Notation (RPN) calculator in Python. Originally it had just 4 operators (using import operator and a ...
3
votes
1answer
77 views

2 way communication Python socket

I'm trying to create a 2 way communication socket in python. The socket will listen for connections from the client until it gets the data formatted in string like this: 'PHONENUMBER|STATUS'. I will ...
0
votes
0answers
21 views

Reload pickled objects into dict - assigned to variable name from file name

I'm doing a bunch of work with echonest audio objects (as returned by the echonest API) in the Python CLI and rather than having to recreate them each time, they can be saved. This bit of code ...
3
votes
2answers
672 views

Tic-Tac-Toe solver

As a programming exercise, I've attempted a Tic-Tac-Toe solver which takes a finished board and determines a winner. On top of checks for malformed input/ambiguous games (e.g. both players with ...
6
votes
1answer
155 views
4
votes
2answers
60 views

Reading and Writing in same script

I just finished working through Exercise 16 of Learn Python The Hard Way. To further study, I wanted to create a script that will read and display a file's contents on screen, and then have the user ...
10
votes
2answers
136 views

Gimme some random passwords

pwgen is a nice password generator utility. When you run it, it fills the terminal with a bunch of random passwords, giving you many options to choose from and ...
1
vote
1answer
37 views

Expiring in-memory cache module

I needed a simple expiring in-memory cache module for a project I'm working on and I've come up with the following. My requirements for the cache module are: Be able to expire objects after certain ...
3
votes
0answers
132 views

Pure Python script that saves html page with all images

Here is pure Python script that saves html page without CSS but with all images on it and replaces all hrefs with path of image on hard drive. I know that there are great libraries like ...
2
votes
1answer
109 views

XOR of a list of a numbers

In preparing a solution for the CodeChef "Will India Win" challenge, I am trying to find out the xor of list of numbers. The first line of input contains the number of test cases, 1 ≤ T ≤ 106. ...
3
votes
2answers
119 views

Create SQLite backups

I have this script for creating SQLite backups, and I was wondering whether you'd have any suggestions on how to improve this. I was thinking that maybe it should create the backup ...
4
votes
1answer
88 views

Universal memoization decorator

I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments combinations it's been ever invoked with. So, if, say, we ...
4
votes
0answers
92 views

Visualize Parts of Song as Analyzed by Echonest

This is the a bit of code that works with Echonest API's pyechonest and remix libraries combined with matplotlib.pyplot to offer a simple visual representation of the start and end "parts" of a music ...
3
votes
1answer
73 views

Iterate over coordinates and correct constraint violations

I am creating an algorithm to take a series of labelled points placed randomly and move them until they fulfil a set of constraints. The constraints have been pre-computed and are each a lower and ...
3
votes
1answer
55 views

Parse data into three logs

In the bit of code below: How can I make add_day, add_ week and add_month work as a single ...
4
votes
4answers
628 views

Squaring an integer by repetitive addition

I've written two functions: is_integer(), which tries to get a positive or a negative integer as input and returns the same value. ...
2
votes
1answer
43 views
3
votes
2answers
60 views

Number of files with specific file size ranges

I am trying to write a script that will traverse through my directory and sub directory and list the number of files in a specific size. For example, 0kb-1kb: 3, 1kb-4kb:4, 4-16KB: 4, 16kb-64-kb:11. ...
3
votes
5answers
171 views

Getting a 4.0 GPA

This is my code, for calculating a GPA for 7 subjects. It works, but is there a better way? Any hints on making it more flexible? ...
7
votes
5answers
692 views

Interactive dice simulator

After finishing my course on CodeAcademy, I wanted to write a program. Please provide opinions. ...
1
vote
1answer
111 views

Transposing rows and columns for file contents [closed]

This program transposes rows and columns for file contents: ...
2
votes
1answer
69 views

Ping function in Python

Below is a piece of code which takes a list of IPs, pings the hosts and returns (prints) the list for "Alive" and "Dead". Any feedback on what can be done better is welcomed, mainly, speed and ...