Questions tagged [python-2.4]

For issues relating to development in Python, version 2.4.

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

Look here for Python 2.4 specific downloads and documentation.

228 questions
145
votes
2 answers

Unpickling a python 2 object with python 3

I'm wondering if there is a way to load an object that was pickled in Python 2.4, with Python 3.4. I've been running 2to3 on a large amount of company legacy code to get it up to date. Having done this, when running the file I get the following…
NDevox
  • 4,056
  • 4
  • 21
  • 36
92
votes
4 answers

How to safely open/close files in python 2.4

I'm currently writing a small script for use on one of our servers using Python. The server only has Python 2.4.4 installed. I didn't start using Python until 2.5 was out, so I'm used to the form: with open('file.txt', 'r') as f: # do stuff…
TM.
  • 108,298
  • 33
  • 122
  • 127
44
votes
8 answers

In Python 2.4, how can I strip out characters after ';'?

Let's say I'm parsing a file, which uses ; as the comment character. I don't want to parse comments. So if I a line looks like this: example.com. 600 IN MX 8 s1b9.example.net ; hello! Is there an easier/more-elegant way…
lfaraone
  • 49,562
  • 17
  • 52
  • 70
41
votes
3 answers

How to make Python format floats with certain amount of significant digits?

I want my Python (2.4.3) output numbers to have a certain format. Specifically, if the number is a terminating decimal with <= 6 significant digits, show it all. However, if it has > 6 significant digits, then output only 6 significant digits. "A"…
user1145925
  • 971
  • 3
  • 13
  • 24
31
votes
5 answers

How to unzip a file with Python 2.4?

I'm having a hard time figuring out how to unzip a zip file with 2.4. extract() is not included in 2.4. I'm restricted to using 2.4.4 on my server. Can someone please provide a simple code example?
Tapefreak
  • 982
  • 1
  • 13
  • 16
30
votes
4 answers

Saving stdout from subprocess.Popen to file, plus writing more stuff to the file

I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to a file. Because the output is sometimes large enough to overwhelm…
jasper77
  • 1,553
  • 5
  • 19
  • 31
22
votes
3 answers

JSON module for python 2.4?

I'm accustomed to doing import json in Python 2.6, however I now need to write some code for Python 2.4. Is there a JSON library with a similar interface that is available for Python 2.4?
kdt
  • 27,905
  • 33
  • 92
  • 139
18
votes
1 answer

Avoiding accidentally catching KeyboardInterrupt and SystemExit in Python 2.4

In Python scripts, there are many cases where a keyboard interrupt (Ctrl-C) fails to kill the process because of a bare except clause somewhere in the code: try: foo() except: bar() The standard solution in Python 2.5 or higher is to catch…
jrdioko
  • 32,230
  • 28
  • 81
  • 120
17
votes
4 answers

Python ConfigParser interpolation from foreign section

With Python ConfigParser, is it possible to use interpolation across foreign sections? My mind seems to tell me I've seen that it's possible somewhere, but I can't find it when searching. This example doesn't work, but it's to give an idea of what…
user16738
  • 1,223
  • 8
  • 10
17
votes
3 answers

Evil in the python decimal / float

I have a large amount of python code that tries to handle numbers with 4 decimal precision and I am stuck with python 2.4 for many reasons. The code does very simplistic math (its a credit management code that takes or add credits mostly) It has…
Ehsan Foroughi
  • 3,010
  • 2
  • 18
  • 20
17
votes
7 answers

telnetlib python example

So I'm trying this really simple example given by the python docs: import getpass import sys import telnetlib HOST = "" user = raw_input("Enter your remote account: ") password = getpass.getpass() tn =…
de1337ed
  • 3,113
  • 12
  • 37
  • 55
14
votes
6 answers

Python try/except not working

Trying to get the try/except statement working but having problems. This code will take a txt file and copy the file that is in location row 0 to location of row 1. It works however if i change one of the paths to invalid one it generates an error…
user1943219
  • 396
  • 2
  • 5
  • 19
13
votes
2 answers

SMTP AUTH extension not supported by server in python 2.4

This is my normal code in my VPS hosting which provide python 2.4 def mail(receiver,Message): import smtplib try: s=smtplib.SMTP() s.connect("smtp.gmail.com",465) s.login("email@gmail.com", "password") …
Hamoudaq
  • 1,490
  • 4
  • 23
  • 42
11
votes
3 answers

Python's foreach backwards

Does python have a means of doing foreach backwards? I'm hoping to do a filter() (or list comprehension) and reverse a list at the same time, so that I can avoid doing it separately (which I suspect will be slower). I'm using python 2.4 (I have to…
shadowland
  • 757
  • 1
  • 6
  • 20
9
votes
2 answers

How to signal alarm in python 2.4 after 0.5 seconds

I want to timeout a particular piece of python code after in runs for 0.5 seconds. So I intend to raise an exception/signal after 0.5 seconds, and handle it gracefully and continue with rest of code. In python i know that signal.alarm() can set…
1
2 3
15 16