Use this tag if you are specifically using Python 2.7. Such questions should be tagged with [python] as well.
3
votes
1answer
61 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
25 views
For and if loops in Python math game [on hold]
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
68 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
43 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.
...
0
votes
0answers
40 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
49 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
2answers
77 views
0
votes
0answers
14 views
How to chain functions using reactor in python? [closed]
My code:
class Server(DatagramProtocol):
...
0
votes
0answers
32 views
How to use nested try/catch in python? [closed]
I have following code, in which i have to handle exception for 2 statements,
2nd line and 4th line
...
1
vote
1answer
55 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
1answer
31 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 (...
3
votes
1answer
57 views
Extracting the text of a specific XML node
I have to extract friendlyName from the XML document.
Here's my current solution:
...
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 ...
0
votes
0answers
20 views
Making this line PEP8-correct [closed]
MS = 'M-SEARCH * HTTP/1.1\r\nHOST: %s:%d\r\nMAN: "ssdp:discover"\r\nMX: 2\r\nST: ssdp:all\r\n\r\n' % (SSDP_ADDR, SSDP_PORT)
On checking this line with PEP8, it ...
6
votes
3answers
77 views
3
votes
2answers
74 views
Python Barcode Generator v2
This is a complete rewrite of the code posted for review in this question. The question is identical.
...
3
votes
2answers
49 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 ...
5
votes
2answers
196 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 ...
7
votes
2answers
486 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 ...
2
votes
1answer
49 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 ...
2
votes
3answers
115 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 ...
7
votes
2answers
121 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
37 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
...
7
votes
5answers
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
502 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
202 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
59 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.
...
5
votes
2answers
111 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 ...
9
votes
1answer
135 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):
...
7
votes
2answers
134 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.)
...
7
votes
3answers
247 views
2-player in a Python hangman game
This is a follow-up: Python Hangman Program
I'm working on adding a few features to my hangman game, and I just implemented two-player gameplay, in the form of one player chooses the word to be ...
3
votes
4answers
53 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 ...
2
votes
2answers
104 views
Speeding up and fixing phone numbers from CSVs with Regex
I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
3
votes
1answer
69 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 ...
2
votes
0answers
40 views
Forcing base class functions to be used from the base class [closed]
The answer to this question is probably "W-what!? What the !@#$-- Stop!! That's a terrible idea!", but I would like to hear your thoughts...
I have two classes and one inherits from the other.
...
6
votes
5answers
183 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.
...
2
votes
1answer
51 views
5
votes
1answer
53 views
Strongly connected components algorithm
In my Python application, I am using Tarjan's algorithm to compute strongly connected components. Unfortunately, it shows up under profiling as one of the top functions in my application (at least ...
8
votes
2answers
81 views
Comparing Server Version Number History
I have this code that compares all version numbers of servers. (The version numbers are stored in an XML file) Before the code would compare the current version number with the previous. This caused ...
7
votes
3answers
148 views
Can this rendition of Project Euler 26 be better written in any way?
This is my solution for problem 26 from Project Euler :
...
9
votes
2answers
416 views
Dice-rolling simulator
I know there is a better way to store data. What is the most concise way to simplify this script?
...
0
votes
1answer
45 views
Dealing with a dirty table
I have to deal with a really ugly looking response I get back from a particular device. The string represents a table. Each section of the string represents the form:
...
2
votes
2answers
73 views
Numbers to Text Program - Python Training
I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about ...
3
votes
1answer
73 views
Ping Pong Pi - A ping pong score and serving manager
I have spent a few hours on this code, but think it could be improved a bit. It requires eSpeak to be installed to run the speech synthesis, but the voice can be toggled on or off using the ...
6
votes
3answers
102 views
Use up all characters to form words
Task:
Given a dictionary of words, and a set of characters, judge if all the
characters can form the words from the dictionary, without any
characters left. For example, given the dictionary ...
4
votes
2answers
157 views
Best way to display big data
I would like to display this data, callable at any time, but I'm not sure if this is the best practice to do so.
...
6
votes
1answer
81 views
9
votes
2answers
351 views
Virtual machine using RPython and PyPy
I'm writing a virtual machine in Python using RPython and the PyPy toolchain. The RPython will still work in the ordinary Python 2 interpreter, it's just a bit slow unless it's compiled to C code with ...
1
vote
1answer
53 views
Script scraper for outputting variables and functions to a text file
I've been programming with Python 2.7 for about six months now and if possible, I'd like some critique to see what I might have done better or what I might be doing wrong.
My objective was to make a ...
6
votes
3answers
257 views
Streamlined for-loop for comparing two lists
I'm new to Python and I'm wondering is there a way to streamline this clunky code I've written. Maybe a built-in function I've never come across before?
I run through two lists of binary numbers and ...