script fichiers binaires lecture écriture

bruno modulix onurb at xiludom.gro
Thu Jun 30 12:26:02 CEST 2005


Statesman wrote:
> In English:
> 
> I don't know much about python and I won't have much time to learn much
> about it even if it seems powerful...
> 
(snip code)

> Here is an error I get trying to run this script:
> 
> AttributeError: 'string' object has no attribute 'index'
> 
> According to me, index() is a method of the string class but not an
> attribute. So I don't understand the error message. 

In Python, functions are first class citizens (a function is an object
you can bind to a variable, pass as an argument, return from another
function etc...), so methods *are* actually attributes...

> Be aware that I'm
> using pyhton 1.5, 
Err... latest is 2.4.1, and the language has really, really changed. You
should consider upgrading...

> unfortunately...

BTW, in 1.5.x, you can use the String module instead of string class
methods:

import String
s = "allo"
String.index(s, "a")

but really, consider upgrading to a newer version...

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list