Questions tagged [python-2.x]

Python 2 is the predecessor of Python 3 and its last version, Python 2.7 was formally released on July 3, 2010. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 2 interpreter only. Do not mix this tag with the python-3.x tag.

Filter by
Sorted by
Tagged with
3
votes
2answers
413 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
87 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 ...
4
votes
2answers
236 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 ...
3
votes
1answer
829 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
1k 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 efficiency,...
2
votes
1answer
385 views

unique_list class

Please review unique_list: unique_list implements a list where all items are unique. ...
6
votes
2answers
2k 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 ...
3
votes
1answer
836 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
75 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 ...
8
votes
4answers
3k 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 ...
11
votes
2answers
783 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. ...
3
votes
1answer
88 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. ...
11
votes
1answer
2k 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
2k 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.) ...
2
votes
2answers
909 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 ...
5
votes
1answer
2k 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 ...
5
votes
1answer
971 views

Improving a triangulation test script

I am a relative beginner to Python and as such I've been working on little things here and there in the office that strike me as something interesting that might be fun to try and code a solution. ...
8
votes
2answers
95 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 ...
0
votes
1answer
63 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: ...
9
votes
3answers
352 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 {...
5
votes
2answers
272 views

Best way to display big data [closed]

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. ...
8
votes
3answers
37k views

Streamlined for-loop for comparing two lists [closed]

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 ...
5
votes
1answer
578 views

Fallout-style homework game

I've been going through LPHW (learn Python the hard way) lessons and I am now at exercise No36 where I have to create a similar game. Could you please review it and point out beginner mistakes? <...
1
vote
1answer
923 views

Depth first search, use of global variables, and correctness of time

As I was coding this algorithm I found that some variables that are meant to be global behave as they are intended to behave, but others do not. Specifically, my boolean arrays, e.g. ...
1
vote
0answers
845 views

Optimize Python script for memory which opens and reads multiple times the same files

I have code that works perfectly, but it uses too much memory. Essentially this code takes an input file (lets call it an index, that is 2 column tab-separated) that searches in a second input file (...
-1
votes
1answer
918 views

Use of multiple value errors in Python [closed]

Review this code. ...
3
votes
1answer
133 views

Is it a good style to run external commands in Python? [closed]

I have lots of external shell commands to run. So I gave every command a name and then run it. ...
10
votes
2answers
3k views

Long constructors, inheritance, class method constructors

My class takes functions as a parameter. There are 6 of them, along with numerous other parameters. Almost all of the fields have default values. It also has a class method that creates an instance ...
10
votes
1answer
189 views

Shortcuts and imports for large RPG basic code

I decided to work on putting together an Arena-style (very basic) text-based RPG as a way to help myself learn Python. Unfortunately, after about 1,000 lines of pieced-together code, I realize that I'...
4
votes
1answer
318 views

Paragraph Matching in Python

So I developed some code as part of a larger project. I came upon a problem with how to match paragraphs, and wasn't sure how to proceed, so I asked on Stack Overflow here. You can find an in-depth ...
13
votes
1answer
8k views

Faster computation of barycentric coordinates for many points

I'm just starting to understand the Python syntax and I created a module that does what I wanted, but really slow. Here are the stats of cProfile, top 10 ordered by ...
3
votes
1answer
659 views

Making this Pygame code object-oriented [closed]

PYTHON 2.7- I want to make my code OOP. I also want feedback from you on correctness, tidiness, design patterns and so on. Here's the download link. It's not permanent but it's the best I have ...
3
votes
1answer
346 views

Function to find midpoint of two floats where one of the floats might be an empty string

There must surely be a nicer way of writing this. The wrinkle of complexity is that prev_seq or next_seq might be an empty ...
4
votes
2answers
379 views

Python coding style from Java background

I am pretty new to Python and just wanted to make sure I am going in the right direction with my coding style. After reading this, I'm not so sure. The following is a convenience class that has ...
6
votes
1answer
299 views

Improvements on Python game?

This is a game I made in Python. While it is not my first, I am not happy with the result. I would like suggestions on ways I can make it better, more user-friendly, and more enjoyable. Also, if ...
2
votes
1answer
92 views

Produce product of lists

I want to combine elements in different lists. For example, here are 3 lists. list_a : [ 1,2,3 ] list_b : [ 4,5,6 ] list_c : [ 7,8 ] Selecting elements from <...
4
votes
2answers
331 views

Text file reading and printing data

MyText.txt This is line 1 This is line 2 Time Taken for writing this# 0 days 0 hrs 1 min 5 sec Nothing Important Sample Text Objective To read the text ...
22
votes
4answers
9k views

Regex to parse semicolon-delimited fields is too slow

I have a file with just 3500 lines like these: filecontent= "13P397;Fotostuff;t;IBM;IBM lalala 123|IBM lalala 1234;28.000 things;;IBMlalala123|IBMlalala1234" ...
2
votes
1answer
3k views

Is this a safe/correct way to make a python LogHandler asynchronous?

I'm using some slow-ish emit() methods in Python (2.7) logging (email, http POST, etc.) and having them done synchronously in the calling thread is delaying web requests. I put together this function ...
3
votes
2answers
13k views

Multiple Choice Quiz with Stat Tracking

I was hoping I could get some of you to look over a program I wrote. I am just beginning to learn about Python (for the last month or so). Therefore, I may not be aware of techniques that would make ...
2
votes
1answer
823 views

Opinions/Improvements on a run periodically/timer function in Python 2.7

I'm looking for some opinions on this bit of code that I wrote and if there are any ways it can be improved. The scripts aim is to run the function runme() every 60 seconds with a random interval ...
10
votes
2answers
3k views

A small Python text adventure “frame”

I've been working on a small "frame" for a text adventure in Python. So it's less of a real adventure and more of a small testing location for all the commands. I pretty much just started learning ...

1
21 22 23 24
25