[Python-Dev] SWIG and rlcompleter

Fernando Perez fperez.net at gmail.com
Tue Aug 16 19:17:04 CEST 2005


Guido van Rossum wrote:
> (3) I think a better patch is to use str(word)[:n] instead of word[:n].

Mmh, I'm not so sure that's a good idea, as it leads to this:
In [1]: class f: pass
 ...:
In [2]: a=f()
In [3]: a.__dict__[1] = 8
In [4]: a.x = 0
In [5]: a.<TAB HIT HERE>
a.1 a.x
In [5]: a.1
------------------------------------------------------------
 File "<console>", line 1
 a.1
 ^
SyntaxError: invalid syntax
In general, foo.x named attribute access is only valid for strings to begin with
(what about unicode in there?). Instead, this is what I've actually
implemented in ipython:
 words = [w for w in dir(object) if isinstance(w, basestring)]
That does allow unicode, I'm not sure if that's a good thing to do.
Cheers,
f


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /