Why these don't work??

Mark Dickinson dickinsm at gmail.com
Thu Apr 8 20:31:47 CEST 2010


On Apr 8, 7:10 pm, "M. Hamed" <mohammed.elshou... at microchip.com>
wrote:
> I'm trying the following statements that I found here and there on
> Google, but none of them works on my Python 2.5, are they too old? or
> newer?
>
> "abc".reverse()

This isn't valid Python in any version that I'm aware of.  Where did
you see it?  It wouldn't make a lot of sense anyway, since by analogy
with list.reverse you'd expect it to reverse the given string in
place.  But that's not possible in Python, because strings are
immutable.

Maybe you're looking for something like:

>>> reversed("abc")
<reversed object at 0x100582810>

which works in versions of Python >= 2.4.

> import numpy

For this to work, you need to have numpy installed.  numpy is a third-
party package that isn't part of the standard Python distribution;
for more information, see:

http://numpy.scipy.org/

The best method for installing numpy would depend on your system, and
on where you got Python from.  On OS X, the system Python comes with
numpy as standard, for example.  On Linux, there's probably a python26-
numpy package (or something with a similar name) that you can
install.  On Windows:  no idea.  :)

Mark



More information about the Python-list mailing list