0
votes
0answers
20 views

Python ADO + ODBC function [migrated]

I am writing a small module to help a transfer from M$-Access to SQLite (database needs to be portable), but I'm struggling in interpreting the error message that follows from this code (and of course ...
1
vote
0answers
46 views

Changing states of a game character and constructor signature

I have an Actor class who represents the player and the NPCs of an game. The Actor have an StateMachine object who manages the push and the pop of the states of the Actor object. The Actor have only ...
1
vote
2answers
41 views

Changing the state of another entity into the constructor method

I have a Clock class who inherites from pyglet.clock.Clock and behaves like a Singleton. Into the constructor method I have the following line: pyglet.clock.set_default(self) Who changes the state ...
1
vote
1answer
65 views

Is there a better way to make a function silent on need?

I got a piece of code I'm not pleased with; Does anyone would have a better idea? def myFunc(verbose=True): if not verbose: print = functools.partial(globals()['print'], ...
1
vote
1answer
64 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, ...
3
votes
1answer
156 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 ...
3
votes
1answer
148 views

Improve efficiency for finding word frequency in text

Premise: Write a program that counts the frequencies of each word in a text, and output each word with its count and line numbers where it appears. We define a word as a contiguous sequence of ...
2
votes
1answer
106 views

Is this a good encryption algorithm?

I've never had a serious attempt at writing an encryption algorithm before, and haven't read much on the subject. I have tried to write an encryption algorithm (of sorts), I would just like to see if ...
3
votes
3answers
156 views

Advice on program which calculates scores for predictions of Football scores

I am writing a program which calculates the scores for participants of a small "Football Score Prediction" game. rules are: if the match result(win/loss/draw) is predicted correctly: 1 point if the ...
6
votes
1answer
216 views

This Python script gets the job done, but what about it is not 'Pythonic'?

I get a lot done with Python scripts but always feel like I'm working with a messy desk when I'm using it. I assume this is because I am not coding in Python correctly. Coming from a C# and Ruby ...
3
votes
1answer
235 views

The Observer design pattern in Python in a more pythonic way (plus unit testing best practices)

I'm continuing to work on the Head First Design Patterns book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is here with ...
1
vote
1answer
874 views

Dynamic programming solution to knapsack problem

I wrote a solution to the Knapsack problem in Python, using a bottom-up dynamic programming algorithm. It correctly computes the optimal value, given a list of items with values and weights, and a ...
2
votes
1answer
186 views

python alternative to complex if-else structure

I've been on stackoverflow looking for an alternative to the ugly if-elif-else structure shown below. The if-else structure takes three values as input and returns a pre-formatted string used for an ...
3
votes
1answer
112 views

Die Roller for command line

I've written a die roller which can be run from the command line. It currently exists as three files, but I'll say later why I'd like to make it four. The files are as follows: die.py: Defines the ...
3
votes
1answer
67 views

Python Optimizing/Speeding up the retrieval of values in a large string

I have a string containing around 1 million sets of float/int coords, i.e.: '5.06433685685, 0.32574574576, 2.3467345584, 1,,,' They are all in one large string and only the first 3 values are ...
7
votes
1answer
165 views

Python __new__ and __init__ usage

I'm trying to write a Python module to handle matrices. (I know about numpy, this is just for fun) So far I have written a few classes, Matrix, Dim, and Vec. Matrix and Vec are both subclasses of ...
7
votes
2answers
215 views

How can I make this command line utility better?

I have been developing a capitalizer in Python. This is actually a script that an end user will type at their terminal/command prompt. I have made this script to: Taking the first argument as a file ...
2
votes
2answers
169 views

What are the bad habits etc. in this code?

I know this code is pretty awful, but, by any chance, could someone point out all the flaws you can find and tell me them? I think it will help me become a better coder. # Alien Assualt # A bullet ...
3
votes
1answer
97 views

How can I improve this python script that counts the number of days worked for all commiters to a git repo?

I wrote this script to collect evidence of the number of days worked for the purpose of claiming some government tax credits. I'm looking for some ways to clean it up, I'm especially wondering if ...
4
votes
2answers
152 views

Reading a controll character in a loop in Python

I have a code snippet bellow and because of habit from other programming languages I wanted to use rather do-while loop. But Python offers only the construct which I show as a second code snippet ...
0
votes
2answers
100 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 ...
1
vote
0answers
98 views

Guidance on SoC and passing data between GUI instances (MVC pattern)

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 ...
6
votes
3answers
919 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 player should ...
1
vote
0answers
156 views

Looking for design and best practices tips in the area of Python and Web Applications

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 ...
2
votes
1answer
143 views

Python RESTful image handler

Firstly, this is a great idea for a new StackExchange site. 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 ...
2
votes
1answer
128 views

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

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 ...
3
votes
2answers
490 views

Help me improve and optimize a Tic-Tac-Toe game I wrote 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 : #!/usr/bin/env python3 import ...
3
votes
1answer
142 views

Review for Python mapping container in which every element is a key

I wanted to have a python container in which every element is a key (like in a set), but still supports mapping (like a dict) between the elements. To get a container which supports this idea the ...
10
votes
1answer
613 views

Optimizing Python Image Viewer and General Code Format Advise

I'm currently making a manga (read: comic) viewer in python. This project has been a code as you learn project, because I have been trying to code this as I learned about Tkinter. Python I have known ...
5
votes
6answers
1k views

Pythonic FizzBuzz Problem

Below are two solutions to the Fizz Buzz problem in Python. Which one of these is more "Pythonic" and why is it more "Pythonic" than the other? Solution One: fizzbuzz = '' start = int(input("Start ...