[C++-sig] Random access iterators, and sequence protocol.

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sat Jul 5 20:06:36 CEST 2003


>>>>> "N" == nicodemus  <nicodemus at globalite.com.br> writes:

    >> To do this __getitem__ needs to generate an IndexError when the
    >> index is greater than or equal to size.  Do I _have_ to
    >> register an exception translator from something like
    >> std::range_error?  Is there an easier way to do this?  The docs
    >> don't reveal any easier solutions.  It would be nice if this
    >> were also as easy as doing it via range, or iterator. :)

    N> Make a wrapper for your __getitem__, that throws IndexError
    N> when an invalid index is passed (untested):

[snip example]

Thanks.  I was aware of that.  I wanted to know if there were an
easier way. :) I guess this should be a fairly common requirement
anyway so having some boilerplate code would be useful.

It struck me that since Pyste files are pure Python files it would
certainly be useful if a *user* could share common functions that
generate code that is common across Pyste files that they have.  To
this end it would be nice if 'import' could work in the directory
where the .pyste file exists.  So perhaps something like this would be
useful in pyste.py::ParseArguments():

    for file in files:
        d = os.path.dirname(os.path.abspath(file))
        if d not in sys.path:
            sys.path.append(d)


That way any of the .pyste files could import others in their
directory without having to resort to doing it in each of their source
files.

Thanks!

cheers,
prabhu




More information about the Cplusplus-sig mailing list