Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
5
votes
1answer
32 views
Saving Player Name Throughout Script Launches
I would like to use this in a program to save users' names even after they relaunch the script. I was just wondering if there were some ways I could clean up this code.
Note: this currently was made ...
4
votes
2answers
719 views
Does this one-line text-based terrain generator go against standards?
This isn't really an actual project, just something I threw together in about 5 minutes. I just want to know if it goes with the current python standards and if anything should be changed.
...
0
votes
2answers
62 views
A small backup script in Python
I work on ubuntu machine and my backup requirements are straightforward. My only requirement is the usual copy paste, but only changed files (ie. the files whose modification-time OR size has changed) ...
2
votes
3answers
75 views
Apple picking game. More efficient method than using global variables
I have been working on a small game called apple picker, it's text-based, and relvolves around picking and selling apples. Unfortunately I've been using global variables for this whole thing and it's ...
3
votes
1answer
28 views
Persistent key value store for Python using SQLite3
This is a module to implement a key value store in Python using SQLite3. Originally written to allow sharing of configuration among multiple threads that are already sharing a SQLite3 database, I have ...
7
votes
3answers
205 views
Saving high scores in a pickle database
Seeking to improve upon my high score 'module' code. It saves users' high score in a pickle database and if needed prints out the current scores in the database.
...
5
votes
1answer
29 views
Refactoring Tkinter GUI that reads from and updates csv files, and opens E-Run files
Background
My lab administers four computer programs in three separate appointments. At each appointment, the subject does the programs in a pseudo-randomized order. Also, three of the programs have ...
7
votes
3answers
143 views
Script for finding cheating students in a quiz
Below is a script to find cheating students in a quiz in a daily moodle activity log exported in .xls. It works fine and is written in a procedural way.
Essentially the script isolates the activity ...
4
votes
2answers
247 views
Manipulating filenames using Python
I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename.
...
2
votes
2answers
73 views
Word counter script
I made a word counter. It works as long as there aren't any lone punctuation marks. How could it be improved? (Could it be made simpler? Are the comments detailed/clear enough? etc.) I know it's ...
5
votes
2answers
124 views
Z-Algorithm for pattern matching in strings
I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings.
...
0
votes
1answer
31 views
Counting Calls in Python [closed]
The problem is as follows:
Design a function that generates the number of steps in the Collatz Conjecture
For more information
Essentially, for a given number, the sequence begins reducing the ...
4
votes
1answer
64 views
Checking for Prime Numbers [closed]
def is_prime(n):
if n % 2 == 0 and n > 2:
return False
return all(n % i for i in xrange(3, int(math.sqrt(n)) + 1, 2))
The code works fine for a ...
2
votes
2answers
86 views
Simple Card Game in Python
After finishing up finals, I wasn't really working on coding for a while. I decided to write a card game to get back into the programming scene. I'm just wondering if there's anything that I missed ...
1
vote
3answers
60 views
Optimization and accepted paradigms
This project was completed as part of an interview challenge.
The feedback I received was:
The code is neither optimized nor does it follow generally accepted paradigms, naming conventions or best ...
3
votes
2answers
139 views
CSV email script efficiency
I'm tasked with getting emails from a .csv file and using them to submit a form. I am using the csv and mechanize Python libraries to achieve this.
...
3
votes
1answer
66 views
Converting JDBC to CSV
One of my first ever jython scripts lets me get comma-separated values out of an RDBMS. I submit it here in hopes that you'll rip me apart. Without further ado, have at it:
...
0
votes
1answer
32 views
For and if loops in Python math game [closed]
I'm trying to get my program to iterate through a loop after a person gets the correct answers to the first question. I feel like there is a better way to do things syntactically.
...
4
votes
2answers
96 views
K-means clustering in Python
The following code uses scikit-learn to carry out K-means clustering where \$K = 4\$, on an example related to wine marketing from the book DataSmart. That book uses excel but I wanted to learn Python ...
4
votes
2answers
49 views
Efficient use of regular expression and string manipulation
The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle.
...
3
votes
2answers
78 views
1
vote
0answers
48 views
A class with a function pointer instead of a generator
I am building TiKZ files, one pdf for each image I have. The purpose is to add text to each separately. The images are legion, so I created a script to generate the text files instead of generating ...
5
votes
4answers
53 views
Number Of Matching Elements In Two Lists
I have many sets of 2 strings. I'm trying to determine the number of matching elements in these 2 strings. The rules are if the strings share a common letter, that's a point, order does matter, but ...
3
votes
1answer
67 views
Extracting the text of a specific XML node
I have to extract friendlyName from the XML document.
Here's my current solution:
...
2
votes
3answers
515 views
Simple hashing code with excessive conditional statements
Any thoughts on my code? It's a simple hashing code that runs from the command line.
There just appears to be a lot of condition if / ...
1
vote
1answer
59 views
Implementing command pattern in Python
I did some study on the command pattern but most of its examples were in Java so, there must be some difference in implementation in Python. I implemented it in Python with some minor differences, ...
3
votes
2answers
55 views
Comparing two partition functions in Python
I have written a partition function in Python (my_partition_adv). I have written this one after reading a similar function from a website. The version of the ...
3
votes
1answer
38 views
Efficient data structure for searching a dictionary of words in python using difflib?
I am trying to write a spellchecker and I wanted to use difflib to implement it. Basically I have a list of technical terms that I added to the standard unix dictionary (...
4
votes
2answers
48 views
Readability in creation of a long output string
Below is a function from a driver that I wrote for and I2C temperature sensor.
The function takes as input the name of the bus and the device's bus address, reads it's status register, and then ...
6
votes
3answers
82 views
3
votes
2answers
88 views
Python Barcode Generator v2
This is a complete rewrite of the code posted for review in this question. The question is identical.
...
2
votes
3answers
133 views
Python Barcode Generator
I was asked to provide some example code for a job interview and didn't have anything to offer, so I wrote the following function.
A barcode generator may seem a bit basic, but there's some logic ...
5
votes
2answers
199 views
Thrice nested “OS” in Python
This Python main is what greets the user to a thrice nested super duper barebones OS. The entire rest of my code isn't bug free but this section is, and it feels dirty anyway. I'd like to know how ...
2
votes
1answer
53 views
Project Euler 39: Integer right triangles
I just finished Project Euler 39:
If p is the perimeter of a right angle triangle with integral length sides, {a, b, c} … For which value of p ≤ 1000, is the number of solutions maximised?
I'm ...
7
votes
2answers
510 views
How random is this password-generating algorithm?
This code's sole purpose is to create a very random password, using letters and numbers.
I think that it fulfills its purpose, but I wonder, could it be done better? I'm not talking about ...
4
votes
2answers
228 views
Python wrapper for the Help Scout API
I started porting an API wrapper from Java to Python for practice. I am looking for ways to improve the readability/maintainability this code.
I have done some reading about "pythonic" style and I am ...
2
votes
1answer
123 views
unique_list class
Please review unique_list:
unique_list implements a list where all items are unique. ...
7
votes
2answers
135 views
More elegant way to round decimals in Python?
I am working with currencies, and so have been using the decimal module to rule out any floating point weirdness in the following maths.
I have to add together a number of decimal amounts, find an ...
1
vote
1answer
108 views
Pythonic loop logic for Tic-Tac-Toe game board
I have a while loop below, but I'm not quite sure if it's the most 'pythonic' thing. I've omitted most of the code, and have the skeletal structure below (but have ...
1
vote
1answer
40 views
Avoiding use of .encode() in rss2html
My concern with this code is the excessive use of .encode('utf-8'). Any advice on refining these functions would be very helpful.
rss2html GitHub repo
...
6
votes
5answers
197 views
Guessing Game in Python
Now that I've got this working, any improvements that I can make to better my code review would be helpful.
...
7
votes
4answers
2k views
Plague Inc. in Python - Extremely Early Stage
I've been working to create a game in Python similar to Plague Inc. and instead of just writing one big clump of code and then getting it reviewed, I wanted to do it stage-by-stage and make it a ...
10
votes
2answers
506 views
“FIZZ BANG BUZZ!” 3,7,11 efficiency
I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively.
...
7
votes
2answers
206 views
Given a page of content, determine shortest snippet containing all search phrases (no order required)
A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
4
votes
1answer
61 views
Loop cleanly through different classes
If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements.
...
9
votes
1answer
146 views
Mafia game simulation engine
I've written a program to simulate a game of Mafia among several bots. Here's the directory structure the program lives in (to make understanding parts of the program easier):
...
5
votes
2answers
125 views
Splitting a list by indexes
I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get ...
7
votes
2answers
144 views
Python Email Program
I've written this email program in Python, and I would like to get some feedback on it. (i.e. closing the server twice after the raw input, etc.)
...
3
votes
1answer
75 views
Is the way I used threading in Python correct?
I'm learning how to use Python with the Raspberry Pi. I successfully followed the tutorial for how to have a Python script run on the Pi to check for new email and turn on a LED if any new messages ...
3
votes
4answers
61 views
Comparing phone numbers across CSVs Python
(continuation from Speeding up and fixing phone numbers from CSVs with Regex)
I'm pulling all of the phone numbers from all CSVs in two different directories, outputting them in a single simple ...