python-2.4

Assigning the answer of a function to a variable?(in python 2.4.4)

Assigning the answer of a function to a variable?(in python 2.4.4) Question: def BSformula(num1): “””my formula””” (num1 – 2.0) * (2 / num1) def main(): number = input(“value”) answer = BSformula(number) print(answer) main() When I run it it always prints “None” >>> value: 6 None >>> How would I assign the answer to a variable? …

Total answers: 1

Unpickling a python 2 object with python 3

Unpickling a python 2 object with python 3 Question: 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 …

Total answers: 2

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

How to make Python format floats with certain amount of significant digits? Question: 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. …

Total answers: 3

How to unzip a file with Python 2.4?

How to unzip a file with Python 2.4? Question: 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? Asked By: Tapefreak || Source Answers: You have to …

Total answers: 5

How to safely open/close files in python 2.4

How to safely open/close files in python 2.4 Question: 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 with …

Total answers: 4

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

Saving stdout from subprocess.Popen to file, plus writing more stuff to the file Question: 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 subprocess.PIPE, …

Total answers: 4

Pickling array.array in 2.4 using cPickle

Pickling array.array in 2.4 using cPickle Question: I am working on a project built on python 2.4 (It is an embedded python project, so I don’t have a choice on the version of python used). Throughout the application, we use array.array to store data. Support for pickling array.array objects was added to pickle (and cPickle) …

Total answers: 4

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

In Python 2.4, how can I strip out characters after ';'? Question: 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 to strip chars …

Total answers: 8