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

learn more… | top users | synonyms

-1
votes
0answers
32 views

Find the bug that makes the numbers not the same [closed]

There's some bug in my code that makes the number of articles different in two calculations when the number should be the same or nearly the same. The first code is: def get_count(self, key): ...
0
votes
2answers
35 views

Extending a simple Python console program with external code. Did I handle this correctly?

I'm a hobbyist Python programmer with not much experience. I wrote some code for a solution to a Tic Tac Toe AI problem on the internet. Then yesterday I wrote a simple console Tic Tac Toe game for ...
1
vote
1answer
61 views

Should I use a class as a class factory in Python?

As a bit of a learning project, I decided to take the concept of proxying objects a bit further and extend it to creating proxy classes which create proxy'd objects. I originally found the idea of ...
3
votes
2answers
64 views

refactor Python code with lots of None type checks

When I wrote this it just felt messy due to the null checks. Any good ideas on how to clean it up would be most appreciated. def getItemsInStock(self): itemsInStock = [] items = ...
1
vote
2answers
37 views

Group key-value pairs in chunks no longer than specified limit

Sometime ago I saw a code which packed key,value pairs into several GET messages. That code had a bug (that is why it was shown to me: as the example of beautiful code which doesn't do what it ...
0
votes
2answers
37 views

Generator to Tuple to List?

I have a method that takes a generator, converts it into a tuple to sort it, then into a list. It works perfectly, but being as I am fairly new to the Python world, I keep asking myself if it is worth ...
1
vote
2answers
71 views

Python Code Review, making a scoreboard

So I want this program to be able to keep track of a number of sports teams, record their names, record their scores, and be able to have one team play another. I want to have the user define a ...
0
votes
1answer
78 views

how to make it simply code than complex one

I'm new to python, I have crated following small script, I just need to improve code if possible simple instead complicated. def convUnixTime(t): expr_date = int(t) * 86400 fmt = '%Y-%m-%d ...
-1
votes
1answer
31 views

How do I make print function refer to something in a function without calling the function again? [closed]

So here is my code to find the number of weeks between two dates. How can I make the output print "There are 'x' weeks until 'future date'" without calling the futureDate() function? from datetime ...
0
votes
1answer
37 views

Proper use or convenience, or both?

In my current project, I am working with a lot of JSON objects that contain arrays, er.. lists so I setup a decorator for convienece when the list is one item or multiple. Even though this is ...
2
votes
2answers
82 views

Criticize my threaded image downloader

I'm going to be working on a much larger version of this program and I just wanted to see if there was anything I should change in my style of coding before I made anything larger. If it wasn't ...
6
votes
2answers
139 views

Constructive criticism for simple Python game

I am trying to start learning python using http://learnpythonthehardway.org I wrote my first game which will follow. It works as far as I can test it. It was done as an exercise for ...
1
vote
4answers
67 views

Being Lispy with Hy, a Python Lisp dialect

I think I'd like to learn Clojure eventually, but at the moment am having fun with Hy, a "dialect of lisp that's embedded in Python." (import socket) (defn echo-upper (sock) (.send c (.upper ...
0
votes
0answers
37 views

A CLI mine sweeper game in Python. Moving in VIM way [closed]

I suddenly want to play mine sweeper, but I have neither a Windows nor a mouse. So I made a CLI mine sweeper game dirty and quickly. The cursor is controlled in VIM way, and all the rest ...
0
votes
0answers
40 views

Please review this mapreduce code that builds a too large index

There's some problem with this code, it builds a too large index (of 16 000 entities when the expected size is 3700): def index(entity): try: edge = datetime.datetime.now() - ...
1
vote
2answers
62 views

Making a 2D dict readable

I am building a 2d dictionary with an altered list at the end Afterwords I want to find the min of each list. Is there a better way to do it? Better being faster or at least less of an eyesore. ...
0
votes
1answer
39 views

Python flask web app, simplification

I am writing web application using flask framework + mongodb. I have an issue, should I use classes for my mongo entities or just use dictionaries for them. class School: def __init__(self, num, ...
1
vote
2answers
63 views

Refactoring in Python

I am trying to learn some re factoring techniques on my own and wanted a few exmaples. I am given the following code: import csv from xml.etree.ElementTree import Element, SubElement, Comment, ...
0
votes
0answers
28 views

Refactoring In Python [duplicate]

I am trying to learn some re factoring techniques on my own and wanted a few exmaples. I am given the following code: import csv from xml.etree.ElementTree import Element, SubElement, Comment, ...
3
votes
4answers
104 views

optimizing code

I an a total newbie, and wish to tap the talent in this forum, any help is appreciated I wrote this code to solve a problem from a John Vuttag book "asks the user to input 10 integers, and then prints ...
0
votes
1answer
40 views

How to modularize this huge file?

This huge file is something that I want to modularize into smaller tigher units. Can you tell me how I can do it? The application is this app.
5
votes
3answers
192 views

Is my code efficient?

This is my first ever python program, I'm taking a text file that looks like this: 77, 66, 80, 81 40, 5, 35, -1 51, 58, 62, 34 0, -1, 21, 18 61, 69, 58, 49 81, 82, 90, 76 44, 51, 60, -1 64, 63, 60, ...
1
vote
3answers
135 views

A Better For Loop

I'm very new to Python, and have a feeling that there's a much better way to implement the following code. It works, I'd just like to clean it up a bit. The purpose is just to create a dictionary with ...
1
vote
2answers
38 views

Best way to animate with tkinter

I am trying to learn how to animate with tkinter. The code below is an example I was able to build. I creates a small 5x5 map of cubes then one of them randomly moves around the screen(preferably on ...
1
vote
0answers
55 views

When is (if ever) monkey-patching acceptable? Is there a better solution to this?

I am working on a project that involves xml parsing, and for the job I am using xml.dom.minidom. During development I identified several patterns of processing that I refactored into discrete methods. ...
5
votes
3answers
344 views

How's my python style?

I'd like to improve my pythons skills. I've been programming in Objective-C, and I'd like to know if there's more pythonics way to do things here. It's a (simple) guesser for game where you need to ...
-1
votes
0answers
23 views

Parsing huge complex xml file with python [closed]

I'm having problem parsing a huge xml document. A snippet of the xml data, as well as my code are below. When I run my code, i get the following result:1, 2, 3, and 4, instead of author(s), title and ...
3
votes
0answers
43 views

Python property() implementation that caches getter while still allowing a setter

For a session implementation I needed a property that caches its getter (since it involves a database lookup) but still allows modifications (e.g. assigning a new user and storing that user's id in ...
1
vote
0answers
91 views

Myth-busting SQLite3 performance w. pysqlite

I've read most of the posts I could find on optimizing SQLite3 performance, such as: How do I improve the performance of SQLite?, Is it possible to insert multiple rows at a time in an SQLite ...
2
votes
2answers
57 views

Pythonic use of logical operators to verify variable validity

More and more I find myself doing these kinds of operations: result = this_variable and this_variable[0].operation() Or: result = search or make_something() My only concern is that it might blur ...
2
votes
1answer
33 views

python httplib snippet

I've written this snippet to extract a review request status from review-board in python. It works well but i'm very new to python and i would like to know if i could write this any better. Should i ...
2
votes
3answers
152 views

Is there any way to make my project Euler#14 solution faster?

I'm solving project euler problems and uploading my solutions to github. Some of my solutions are just based on math and are thanks to that very fast, but #14 is way too slow, and I have no idea how ...
0
votes
1answer
69 views

Is there a better way to count seconds in python

def stopWatchSeconds(secondCnt) : """ counts second for secondCnt seconds """ # is there a better way to do this? startTime = time.clock() ellapsed = 0 for x in range(0, ...
2
votes
2answers
48 views

Two dimensional unit testing

Consider a process composed of three algorithms: makeRuns, meld and traverse (each taking the output of the previous one as input): it is interesting to test each separately. Now consider three (or ...
4
votes
1answer
40 views

Optional argument for which None is a valid value

I have the following function: def item_by_index(iterable, index, default=Ellipsis): """Return the item of <iterable> with the given index. Can be used even if <iterable> is not ...
0
votes
0answers
23 views

Building an interface to search a .txt file depending on the user input, then print the results next to it

I've been playing around with this quite a bit and I feel like I'm making a mess of it. I need an interface where if someone enters a word in the text field, it'll print any lines within a .txt file ...
2
votes
1answer
28 views

Generic test serie for various solutions to the same algorithmic problem

I am learning how to use the module unittest for test-driven development. Below is a simple yet practical example of an issue I will have many times: one single problem (e.g. an Abstract Data Type ...
0
votes
1answer
33 views

Python. Leaving a APScheduler in a while True loop

I want to run a background job on my webserver to do some database maintenance. I am looking at using APScheduler to do this. I am planning on running the below code in a separate process to my main ...
1
vote
0answers
36 views

Any side effects from this Python logging code?

def _getCallerLogger(): caller = inspect.currentframe().f_back.f_back name = "{}-{}".format(caller.f_globals['__name__'], caller.f_code.co_name ) logger = logging.getLogger(name) ...
-2
votes
0answers
30 views

creating a question with multi choice answers? Help *python* [closed]

I am trying to create a set of questions maybe 10-20 with multiple choice answers for example I want to create a program that will help people learn division. eg. 10 ÷ 2 = ? 1. 2 2. 9 3. 5 4. 7 ...
3
votes
0answers
107 views

Python: How do I optimize the solving of ODEs?

I have been trying to figure out a way to optimize the solving of ODEs in Python but haven't been able to achieve this goal. I tried getting help via a bounty on SO using cython but nothing came of ...
2
votes
2answers
80 views

cleaner way to import “izip” for different versions of python

A common idiom that I use for python2-python3 compatibility is: try: from itertools import izip except ImportError: #python3.x izip = zip however, a comment on one of my stackoverflow ...
1
vote
1answer
73 views

I need my code to be more consise and I don't know what is wrong with it :/ its pretty basic and I need help [closed]

#Goal: Write a program that asks the user to input 10 integers, and then #prints the largest odd number that was entered. If no odd number was #entered, it should print a message to that effect. ...
1
vote
0answers
88 views

Python script to parse email and create HTML markup from attachments

Disclaimer: I want to apologize right off the bat since this will most likely be a very long-winded post. For those that do not care about/need the details, links to my code and supporting files are ...
2
votes
2answers
64 views

Global variables in python, bottle microframework

I'm sort of at a loss for what to do with webapps and whether what I'm doing is actually allowed or not. Here is a sample of the type of thing i'm doing at the moment. I need a list that is accessible ...
2
votes
1answer
85 views

I'm a beginner who could use some help rewriting messy code. Would anyone care to lend assistance?

I know that this is a complete mess and does not even come close to fitting PEP8. That's why I'm posting it here. I need help making it better. I'm trying to become a better programmer. If this is ...
2
votes
1answer
53 views

Performance and design question

I'm working on a web application using bottle, and it is, at this point, functional. The gist of it is that i have a database of drinks, with associated IDs, and associated sets of ingredients. the ...
4
votes
1answer
175 views

Optimizing python code for big data sets

I'm trying to optimize a python string that works on big data sets, the way it works is by taking in a with a list of keywords and scores and taking in a file loaded with data from the twitter api. ...
3
votes
1answer
89 views

Computation of Prefix Free Codes with many repeated weight values in reduced space

Does the code below respect Python programming conventions? (and if not, which one does it disrespect?) The objective would be to publish this code as part of a scientific article, as "reproducible ...
2
votes
1answer
44 views

Class for simple python object to be hashed and referenced

I need objects in python that I can compare, reference to and hash. In principal a tuple or list would be good enough just that a list I cannot hash and the tuple I cannot change, except replacing it ...

1 2 3 4 5 17