Questions tagged [python-2.5]

For issues relating to development in Python, version 2.5.

Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Version 2.5 is no longer maintained.

For information on Python in general, visit .

Look here for Python 2.5 specific downloads and documentation.


Tagging recommendation:

Use the tag for all Python related questions. If you believe your question includes issues specific to the incompatible Python 2.x or Python 3.x, in addition to the main tag, use or . If you believe your question may be even more specific, you can include a version specific tag such as .

381 questions
207
votes
2 answers

What does from __future__ import absolute_import actually do?

I have answered a question regarding absolute imports in Python, which I thought I understood based on reading the Python 2.5 changelog and accompanying PEP. However, upon installing Python 2.5 and attempting to craft an example of properly using…
Two-Bit Alchemist
  • 17,966
  • 6
  • 47
  • 82
148
votes
5 answers

Python: avoid new line with print command

When I use the print command, it prints whatever I want and then goes to a different line. For example: print "this should be"; print "on the same line" Should return: this should be on the same line but instead returns: this should be on the…
Javicobos
  • 1,485
  • 2
  • 10
  • 6
82
votes
10 answers

How can I obtain the image size using a standard Python class (without using an external library)?

I am using Python 2.5. And using the standard classes from Python, I want to determine the image size of a file. I've heard PIL (Python Image Library), but it requires installation to work. How might I obtain an image's size without using any…
eros
  • 4,946
  • 18
  • 53
  • 78
75
votes
9 answers

Check if input is a list/tuple of strings or a single string

I've a method that I want to be able to accept either a single string (a path, but not necessarily one that exists on the machine running the code) or a list/tuple of strings. Given that strings act as lists of characters, how can I tell which kind…
mavnn
  • 9,101
  • 4
  • 34
  • 52
70
votes
7 answers

Tell if Python is in interactive mode

In a Python script, is there any way to tell if the interpreter is in interactive mode? This would be useful so that, for instance, when you run an interactive Python session and import a module, slightly different code is executed (for example,…
Chinmay Kanchi
  • 62,729
  • 22
  • 87
  • 114
68
votes
4 answers

How to properly use python's isinstance() to check if a variable is a number?

I found some old Python code that was doing something like: if type(var) is type(1): ... As expected, pep8 complains about this recommending usage of isinstance(). Now, the problem is that the numbers module was added in Python 2.6 and I need to…
sorin
  • 161,544
  • 178
  • 535
  • 806
64
votes
2 answers

Subclassing int in Python

I'm interested in subclassing the built-in int type in Python (I'm using v. 2.5), but having some trouble getting the initialization working. Here's some example code, which should be fairly obvious. class TestClass(int): def __init__(self): …
me_and
  • 15,158
  • 7
  • 59
  • 96
58
votes
5 answers

How does Python's "super" do the right thing?

I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
51
votes
5 answers

Sort nested dictionary by value, and remainder by another value, in Python

Consider this dictionary format. {'KEY1':{'name':'google','date':20100701,'downloads':0}, 'KEY2':{'name':'chrome','date':20071010,'downloads':0}, 'KEY3':{'name':'python','date':20100710,'downloads':100}} I'd like the dictionary sorted by…
user479870
38
votes
10 answers

Read data from CSV file and transform from string to correct data-type, including a list-of-integer column

When I read data back in from a CSV file, every cell is interpreted as a string. How can I automatically convert the data I read in into the correct type? Or better: How can I tell the csv reader the correct data-type of each column? (I wrote a…
wewa
  • 1,628
  • 1
  • 16
  • 35
36
votes
5 answers

How to: Macports select python

When I enter: port select --list python This is the result: Available versions for python: none python25 (active) python25-apple python26-apple python27 python27-apple I thought when I use python I would be using version…
kadrian
  • 4,761
  • 8
  • 39
  • 61
31
votes
6 answers

How to parse a RFC 2822 date/time into a Python datetime?

I have a date of the form specified by RFC 2822 -- say Fri, 15 May 2009 17:58:28 +0000, as a string. Is there a quick and/or standard way to get it as a datetime object in Python 2.5? I tried to produce a strptime format string, but the +0000…
millenomi
  • 6,569
  • 4
  • 31
  • 34
29
votes
4 answers

How can I list the methods in a Python 2.5 module?

I'm trying to use a Python library written in C that has no documentation of any kind. I want to use introspection to at least see what methods and classes are in the modules. Does somebody have a function or library I can use to list the functions…
Evan Kroske
  • 4,506
  • 12
  • 40
  • 59
28
votes
4 answers

How do I zip the contents of a folder using python (version 2.5)?

Once I have all the files I require in a particular folder, I would like my python script to zip the folder contents. Is this possible? And how could I go about doing it?
Amara
  • 13,839
  • 9
  • 32
  • 28
25
votes
6 answers

Access to errno from Python?

I am stuck with a fairly complex Python module that does not return useful error codes (it actually fails disturbingly silently). However, the underlying C library it calls sets errno. Normally errno comes in over OSError attributes, but since I…
user79758
1
2 3
25 26