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
2k views

urllib proxy access function

Several of my Python 2.7 programs need to access server tasks via our server Apache instance. The 'client' programs will run on Windows in various environments. They may be run on systems that do not ...
3
votes
1answer
765 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 ...
22
votes
4answers
8k 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" ...
5
votes
1answer
2k views

“Heads or Tails?” guessing game in Python

I'm pretty new to coding and I want to get an opinion on my coding. I am learning Python and I made a really simple heads and tails guessing game. ...
1
vote
2answers
568 views

Python array literal syntax sugar similar to Perl and Ruby

Background Python (version 2.7.2) Problem You want to specify an array in your code. You want to use the 'syntax sugar' available in Ruby and Perl. You are a fanatic about readable code but also ...
7
votes
1answer
178 views

Out of order class resequencer

I got bored recently and wrote a tool to re-order out of order classes in Python files. This can occur with some auto-generation code tools for databases and the like; these files can sometimes be ...
2
votes
2answers
1k views

Optimizing SPOJ edit distance solution

I was doing a standard problem of DP (dynamic programming) on SPOJ Edit Distance using Python. ...
5
votes
2answers
322 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 ...
2
votes
1answer
767 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 ...
12
votes
3answers
12k views

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 ...
1
vote
3answers
932 views

SPOJ “Pesel” challemge

Here is a solution to the SPOJ's JPESEL problem. Basically the problem was to calculate cross product of 2 vectors modulo 10. If there is a positive remainder, it's not a valid PESEL number; (return <...
2
votes
1answer
369 views

unique_list class

Please review unique_list: unique_list implements a list where all items are unique. ...
3
votes
2answers
216 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
2k views

Finding the mode of an array/iterable

I'm currently using SciPy's mode function to find the most occurring item in different iterable objects. I like the mode function because it works on every object type I've thrown at it (strings, <...
4
votes
2answers
510 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 ...
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 ...
4
votes
1answer
1k views

Filtering lines in a log file using multiple regexes

In python2.7: 2 for loops are always a little inefficient, especially in python. Is there a better way to write the following filter function? It tags a line from a log file, if it is useful. ...
9
votes
1answer
3k views

Learn Python the Hard Way #48 — lexicon exercise

I'm trying to get some feedback on my code for the lexicon exercise (#48) in Learn Python the Hard Way. I have only recently started learning Python and want to make sure I have my fundamentals down ...
5
votes
3answers
1k views

Printing a score sheet for baseball batters

I've been learning Python 2.7 for about a week now and have written a quick program to ask for names of batters and printing a score sheet. I have then added the names to a list which I will use more ...
3
votes
1answer
3k views

Abstractness of Shape class

Shape represents an abstract class and the other two classes inherits from it. This looks insufficiently abstract to me. How could I improve it? ...
3
votes
3answers
704 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 / ...
4
votes
4answers
9k views

Comparing 2 CSV files

Here's the exercise in brief: Consider the following file: Code: before.csv A; ; B; B; A; H; C; ; D; D; C; G; E; D; F; F; E; H; G; D; ; H; G; ; ...
14
votes
3answers
20k 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 ...
9
votes
3answers
2k views

Stack Overflow user info fetcher

I'm starting to look at Python and its facilities. I've just tried to make one simple program using some base libraries. I would like to hear some comments about anything you've noticed - style, ...
8
votes
1answer
6k views

Keeping remote folders in sync with local ones

This started as a hacked-together tool to remove annoyances I was facing with experimenting with code on live remote servers, then getting that code into my development environment after experimenting....
3
votes
1answer
4k views

Reading a large XML file and parsing necessary elements into MySQLdb

I have fair concept in a programming (learner) but not an expert to refactor code at the highest level. I am trying to read a huge (100MB-2GB) XML file and parse necessary element (attributes) from a ...
3
votes
1answer
690 views

i18n translator using Jinja2

I'm learning to Jinja2 and what's important in this case isn't speed but i18n translations and functionality. With Python 2.7, Jinja2 and not Django seems to preferred way to go, so I'm rewriting much ...
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 ...
5
votes
1answer
665 views

Random Topic Generator

I've written a python module that randomly generates a list of ideas that can be used as the premises for furthur research. For instance, it would be useful in situations where a new thesis topic is ...
5
votes
1answer
319 views

Suggestions for a Profiler class in Python

Here's what I've right now: ...