Project

Profile

Help

PyXdmArray as_list not working

Added by Martin Honnen over 2 years ago

I had hoped that SaxonC 11.1 makes it easy to use Python lists as XDM arrays and Python dictionaries as XDM maps but so far I am running into issues, there is a method https://www.saxonica.com/saxon-c/doc11/html/saxonc.html#PyXdmArray-as_list documented but when I try to use it I get an error:

from saxonc import *

with PySaxonProcessor(license=False) as proc:
    print("Test SaxonC on Python")
    print(proc.version)
    
    list1 = [1,2,3]
    
    print(list1)
    
    xdmValueList1 = [proc.make_integer_value(i) for i in list1]
    
    print(xdmValueList1)
    
    xdmArray1 = proc.make_array(xdmValueList1)
    
    print(isinstance(xdmArray1, PyXdmArray))
    
    list1FromXdmArray = xdmArray1.as_list()

gives

Test SaxonC on Python
SaxonC-HE 11.1 from Saxonica
[1, 2, 3]
[1, 2, 3]
True
Traceback (most recent call last):
  File "C:\Users\marti\OneDrive\Documents\xslt\blog-xslt-3-by-example\saxonc-11.1-python\arrays-and-maps\makeXdmArrayFromPythonListTest2.py", line 19, in <module>
    list1FromXdmArray = xdmArray1.as_list()
  File "saxonc.pyx", line 4495, in saxonc.PyXdmArray.as_list
    count = derivedaaptr.arity()
NameError: name 'derivedaaptr' is not defined

Any comment as to whether that should work or how to get a Python list from a PyXdmArray?


Replies (4)

Please register to reply

RE: PyXdmArray as_list not working - Added by O'Neil Delpratt over 2 years ago

HI Martin,

Thanks for your post. Currently investigating your issue. On my linux box I am not seeing this failure. See my output below:

Test SaxonC on Python
SaxonC-HE 11.1 from Saxonica
[1, 2, 3]
[1, 2, 3]
True

I will next try the same program on Windows. Its a strange error because it is not recognising the derivedaaptr variable so something strange is going on.

RE: PyXdmArray as_list not working - Added by O'Neil Delpratt over 2 years ago

Please ignore my last message I have reproduced the error:

Traceback (most recent call last):
  File "martin_example2.py", line 20, in <module>
    list1FromXdmArray = xdmArray1.as_list()
  File "saxonc.pyx", line 4495, in saxonc.PyXdmArray.as_list
    count = derivedaaptr.arity()
NameError: name 'derivedaaptr' is not defined

RE: PyXdmArray as_list not working - Added by O'Neil Delpratt over 2 years ago

I have created the following bug issue to keep track of the fix : #5270

Bug has been fixed.

RE: PyXdmArray as_list not working - Added by O'Neil Delpratt over 2 years ago

As a side issue the as_list method has a bug: The values have not been created as their subclasses. I have created another bug issue to track this: #5279

    (1-4/4)

    Please register to reply