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
1
vote
1answer
152 views

Best way to test for required attributes of a classes __init__ method

I have recently been trying to improve the quality of my code. Towards this goal I want to start writing unit tests and I also am trying to implement things i have read as best practices. I have read ...
0
votes
1answer
91 views

How would you improve this point of interaction between Python and Javascript?

I'm writing a checkout form for purchasing online tests. You can buy a certification or a recertification, as well as a pdf or book study manual. I'm using Jinja2 templates to provide test data into ...
5
votes
1answer
289 views

Find the smallest regular number that is not less than N (Python)

This is from an answer to my own StackOverflow question on how to efficiently find a regular number that is greater than or equal to a given value. I originally implemented this in C# but translated ...
2
votes
1answer
9k views

Zeller's algorithm in Python

I have implemented Zeller's algorithm in Python to calculate the day of the week for some given date. I would like to get some feedback on how I can make the code shorter and more elegant: ...
4
votes
1answer
94 views

Improve on python public interface data parser

I would love some thoughts on this class that a wrote to extract user information from a logfile line. I'm concerned about design patterns and the complexity of the code. The extract_user method ...
4
votes
1answer
65 views

Better way to refer to common elements in a sequence of objects?

I just posted this code in SO and one person said my code sucked, and that I should post it here. So here it is (with fix I asked for included, so you don't have to worry about that). The main ...
6
votes
3answers
1k views

python: is my program optimal

I wrote code in python that works slow. Because I am new to python, I am not sure that I am doing everything right. My question is what I can do optimally? About the problem: I have 25 *.json files, ...
0
votes
1answer
284 views

Python server that only returns error 418 [closed]

For this project, I'm using a small piece of Python code to return an error 418 to any request. I'm interested in knowing if there is a much smaller piece of code that does the same thing. ...
7
votes
1answer
177 views

Calculate highscores based on sales data

The background is my question is SO How to create a list of totals for durations? where I found a recursive solution that I want to review. I could not test it for higher levels than 1 but to the best ...
5
votes
2answers
817 views

Transforming a Python dictionary into CSS

Recently I had the idea to write a module for the transformation of the dictionary into valid CSS code. And I would like to hear your comments on my code. License MIT, BSD etc. The code is very ...
3
votes
4answers
5k views

Binary/decimal/hex converter using Tkinter

I debated long and hard before posting this question, and I did a lot of experimenting. I just can't seem to work out an 'elegant', concise way to get done what I want done in the manner I want it ...
4
votes
3answers
271 views

Python dictionary usage [closed]

I create python dictionary based on the parsed data: ...
6
votes
2answers
2k views

Word frequency generator in Python

Please critique my word frequency generator. I am a beginner programmer so any criticism are welcome. Original Code: http://pastebin.com/rSRfbnCt Here is my revised code after the feedback: ...
3
votes
2answers
759 views

Text parser implemented as a generator

I often need to parse tab-separated text (usually from a huge file) into records. I wrote a generator to do that for me; is there anything that could be improved in it, in terms of performance, ...
3
votes
1answer
3k views

Using temporary file as backing object for a tarfile

I have existing code that handles a tarball and would like to use that to process a directory, so I thought it would be reasonable to pack the directory up in a temporary file. I ended up writing: <...
5
votes
2answers
2k views

A generic REST API consuming Python library

I wrote this, which essentially acts as a single library for all possible REST services. Here is the main file, as of alpha version 1: ...
2
votes
1answer
6k views

Python program for converting scientific notation to fixed point

I had to replace all instances of scientific notation with fixed point, and wrote a Python script to help out. Here it is: ...
5
votes
2answers
52k views

Python 'check if number is divisible by 2' program

I have written a simple python program which takes a number from the user and checks whether that number is divisible by 2: ...
2
votes
2answers
1k views

Spotify Bestbefore Coding Challenge in Python

I'm trying to solve the Spotify bestbefore programming challenge found here http://www.spotify.com/us/jobs/tech/best-before/ I have written the code in Python but when I send it in, it says "Wrong ...
6
votes
2answers
600 views

Euler 35 - python solution taking too long

Here is my solution for Project Euler 35. (Find the number of circular primes below 1,000,000. Circular meaning all rotations of the digits are prime, i.e. 197, <...
6
votes
1answer
178 views

Recording loans of access cards to people in a company [closed]

I'm fairly new to Python and currently building a small application to record loans of access cards to people in a company. I'm using wxPython for the GUI and SQLAlchemy for the CRUD. I'm loosely ...
14
votes
3answers
22k views

Character creator for a role-playing game

Goal: Write a character creator program for a role-playing game. The player should be given a pool of 30 points to spend on four attributes: strength, health, wisdom, and dexterity. The ...
2
votes
1answer
171 views

Parsing files with county codes

I am running through a file and inserting elements one by one. The counties all contain specific county codes which are duplicated many times throughout the file. I am looking for a way to assign ...
2
votes
1answer
94 views

How can I make handling multiple {}.get('value', {}.get('foo')) pretty?

I ran into an issue where I was doing this: dictionary1 = {} dictionary2 = {} foo = dictionary1.get('foo', dictionary1.get('bar', dictionary2.get('baz'))) I.e. ...
4
votes
2answers
691 views

Spotify puzzle problem in python

I'm a complete beginner in Python and programming in general. I made a program for Spotify's Best Before puzzle. It was accepted. I have looked a litle around on internet and looked at other solutions ...
5
votes
1answer
162 views

Checking which pypi packages are Py3k-only

I looked at the pypi classifiers and some guide to help me write the following script, and here's me wondering if it can be improved: ...
6
votes
4answers
2k views

Faster way to create linked list of length n in Python

I'm attempting to create a linked list of length n using Python. I have the simple list implemented, a working concatenation function, and a working create_list function; however, I just want to know ...
20
votes
4answers
71k views

Flattening a dictionary into a string

Given: k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999} I want to flatten into the string: ...
10
votes
3answers
2k views

Stack Overflow user info fetcher

I'm starting to look at Python and its facilities. I've just tried to make one simple program using some base libraries. I would like to hear some comments about anything you've noticed - style, ...
1
vote
1answer
3k views

Tortoise and hare cycle detection algorithm using iterators in Python

Reading the article in Wikipedia about cycle detection I came across a relatively small code snipped of Floyd's cycle-finding algorithm. I'll put it here to keep everything in one place: ...
4
votes
4answers
303 views

is there a better way than replace to write this function?

I am doing my homework and i have done this? Is there any other better way to do this? ...
4
votes
2answers
341 views

Decorator to take away repetitive code

I'm using django and I wrote this decorator to take away some of the repetitive code I found for ajax views and I want to know your opinion (too basic, bad design, try this instead, etc). ...
5
votes
2answers
533 views

Photo changer loop

I just started Python a few days ago, and I haven't programmed much before. I know my code is terrible; however, I would like someone to look it over. What I'm trying to do is create a photo "loop" ...
6
votes
1answer
317 views

Contest assist web app

This is a small web application that I have created using the Flask framework. I am looking for best practices feedback, as well as design pointers. I am not confident that my design choices have ...
6
votes
1answer
677 views

Memory issues with Find Strings Problem on InterviewStreet

Here is the code I wrote for the problem at http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac where we need to to print the substring at a particular index from ...
0
votes
1answer
881 views

Python xml schema parsing for simpleContent and simpleTypes

I am writing a few python functions to parse through an xml schema for reuse later to check and create xml docs in this same pattern. Below are two functions I wrote to parse out data from ...
5
votes
6answers
903 views

40 million tweets from 200k users

...
3
votes
2answers
498 views

Project Euler, #4: Incorrect Results on 7-digit numbers

I've got my answer working (up until a 7-digit answer is requested, anyway), and would like some help returning the correct answer speeding up the results I was thinking of storing the values of ...
2
votes
2answers
213 views

CoderCharts puzzle optimization

This is my solution to the codercharts problem http://codercharts.com/puzzle/word-swap but if keeps failing when I submit the solution because of the cpu_excess_time...
2
votes
2answers
3k views

Python and computing checksums

I have this module which computes checksums from a list of files in a given directory. The problem is that my is_changed_file is long and ugly, but my attempts in refactoring failed, so I would like ...
7
votes
4answers
1k views

Project Euler #14 - Longest Collatz sequence

I'm attempting some Project Euler problems in an attempt to learn Python. While I can get the correct answer quite easily, my programs are quite slow. Project Euler, if doing it correctly, specifies ...
3
votes
1answer
445 views

Payment system for a web shop

I've tried making a payment system for an API called Payson, which is a European company similar to PayPal. I get the right response when I press the button so it seems to work, and I wonder if you ...
4
votes
1answer
4k views

Dictionary-based dispatch in Python with multiple parameters [closed]

Is there a better way to express the dispatch (switch) code without using a lambda? I think I need the lambda to act as an intermediary because the functions have varying numbers of parameters. ...
6
votes
2answers
1k views

Extracting a div from parsed HTML

It seems that lxml/etree are generally imported as from lxml import etree -- why is that? It keeps the code tidier, and while the potential namespace ambiguity ...
2
votes
2answers
1k views

Inefficient Python script eating up memory (I believe)

I created a simple Python script to log track listens in iTunes and it seems that it's pretty inefficient. I'm primarily a front-end developer, so this is clearly not my area of expertise. I know ...
4
votes
1answer
580 views

A better way to convert an SQLObject instance into a dict

I've got this function which returns an SQLObject instance as a dict (taking into account inherited classes, properties, etc). It doesn't work right now on SQLObject classes which inherit from ...
8
votes
1answer
6k views

Keeping remote folders in sync with local ones

This started as a hacked-together tool to remove annoyances I was facing with experimenting with code on live remote servers, then getting that code into my development environment after experimenting....
1
vote
1answer
139 views

Nginx cache path function

I have an MD5 hash string: _hash = '743a0e0c5c657d3295d347a1f0a66109' I want to write function that splits passed string to path in nginx cache format: ...
4
votes
3answers
9k views

Finding duplicate strings within a file

This code basically finds duplicate strings within a file. An example: DUPLICATE_LENGTH set to 6, file contains: ...
4
votes
2answers
152 views

Date and time of an article in a humanized and localized way

The goal is displaying the date and time of an article in a humanized and localized way: Yesterday 13:21 or if the Swedish language parameter is set it will ...

1
268 269
270
271 272
274