[sword-devel] Python bindings and dynamic cast

Ben Morgan benpmorgan at gmail.com
Wed Mar 19 16:47:02 MST 2008


Hi,

Step 2 can be done using
VerseKey.castTo(swkey)

castTo will return None if it cannot cast to it (it uses dynamic cast).
This will happen if (for example) the range is Genesis 1:1, in which
case it seems to just return a SWKey.

Most of the wrapped classes have castTo for them.

If you want to see how it is done in BPBible, look at
http://code.google.com/p/bpbible/source/browse/trunk/swlib/pysw.py

I have a class there called VerseList, which acts more like a list,
and supports things like converting to nice strings (e.g. Genesis
1:1-10 instead of Genesis 1:1-Genesis 1:10).

God Bless,
Ben
-------------------------------------------------------------------------------------------
The Lord is not slow to fulfill his promise as some count slowness,
but is patient toward you, not wishing that any should perish,
but that all should reach repentance.
2 Peter 3:9 (ESV)

On Thu, Mar 20, 2008 at 10:39 AM, Luke Plant <L.Plant.98 at cantab.net> wrote:
> Hi,
>
>  I've been trying to use Sword with Python bindings to simply get a
>  list of verses with a reference like "Genesis 1:1-10".  All the
>  example code I can find, including code I have written in the past,
>  uses a dynamic cast:
>
>  1) VerseKey::ParseVerseList() is used, which returns a ListKey*
>  2) A dynamic cast is done to return a VerseKey*
>  3) Then VerseKey::UpperBound() and VerseKey::LowerBound() are used in
>  iterating over the verses.
>
>  The problem is, I can't work out how to do step 2) or equivalent in
>  Python.  I'm using the standard Python bindings, built from
>  sword-1.5.9/bindings/swig/
>  Help would be much appreciated.
>
>  Thanks,
>
>  Luke
>
>  --
>  "Ineptitude: If you can't learn to do something well, learn to enjoy
>  doing it poorly." (despair.com)
>
>  Luke Plant || http://lukeplant.me.uk/
>
>  _______________________________________________
>  sword-devel mailing list: sword-devel at crosswire.org
>  http://www.crosswire.org/mailman/listinfo/sword-devel
>  Instructions to unsubscribe/change your settings at above page
>



More information about the sword-devel mailing list