multiple object constructors for a single function call

32 views
Skip to first unread message

Romain Bodson

unread,
Oct 21, 2024, 2:33:59 AM10/21/24
to xlSlim Support
Hello,
First of all, thank you for making xlslim available, it's very useful.

I am running xlSlim 3.3.1.0

I'm trying to run a function that takes 4 objects as arguments and returns another object as the result. If I build my objects separately from my function, no worries. Ex :
A1 = object1(arg1, arg2, ...)
A2 = object2(arg1, arg2, ...)
A3 = object3(arg1, arg2, ...)
A4 = object4(arg1, arg2, ...)
obj = function(A1, A2, A3, A4)

However, if I construct my objects in my function, it doesn't work. EX: function(object1(arg1, arg2, ...), object2(arg1, arg2, ...), object3(arg1, arg2, ...), object4(arg1, arg2, ...))

However, if I only construct a single object in my function then it works. Ex : function(object1(arg1, arg2, ...), A2, A3, A4)

Does xlslim allow several constructors to be called in the same function call?

Thank you for your reply,
kind regards
BODSON Romain

xlSlim Dev

unread,
Oct 21, 2024, 2:44:52 AM10/21/24
to Romain Bodson, xlSlim Support
Hi Romain,

I am glad you find  xlSlim to be useful.

This does seem curious, I would expect both ways of calling the function to work. 

Could you share the Python functions you are calling please? Just the function signatures with any type hints.

I will have a look and get back to you.

All the best,
Russel 

--
You received this message because you are subscribed to the Google Groups "xlSlim Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xlslim-suppor...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/xlslim-support/5a8b8e62-6d14-4ed2-893d-6edade2d0752n%40googlegroups.com.

Romain Bodson

unread,
Oct 21, 2024, 5:55:57 AM10/21/24
to xlSlim Support
Thank you for your reply.
here's an example: data_class.py contains the definition of the classes, function_ex.py contains a function that calls another (add_value in function_ex_2.py)

In excel i have #ERR the function call failed - 'LateralBuckling' object has no attribute 'My_Ed1' if I construct my objects in my function.

But if I build my objects separately from my function then it works and excel returns the values correctl. 

Moreover, i have good return if i don't call add_value in my function.

I hope the information is sufficient, if not please don't hesitate.
Thank you for your help.
Romain
function_excel.xlsx
function_ex.py
data_class.py
function_ex2.py

xlSlim Dev

unread,
Oct 21, 2024, 1:46:14 PM10/21/24
to Romain Bodson, xlSlim Support
Thank you for the detailed response. The included files will make it far easier for me to investigate this issue. 

Please give me some time to look into this. I will get back to you soon.

Regards,
Russel 

xlSlim Dev

unread,
Oct 23, 2024, 12:55:06 PM10/23/24
to xlSlim Support
Hi Romain,

I've found the cause of the observed behaviour.

When a Python function returns a Python object, xlSlim automatically puts the object in an internal object cache and returns a cache key. The cache key is composed from the sheet name and address of the cell running the function. So what was happening when you have a cell A1 running a function like this: function(object1(arg1, arg2, ...), object2(arg1, arg2, ...), object3(arg1, arg2, ...), object4(arg1, arg2, ...)) is that object1 is created and put in the cache with a key similar to "[Sheet1]A1", object2 is then created but has the same cache key so it is put in the cache under the same key and overwrites object1, object3 is then created and saved in the cache overwriting object2, finally object4 is created overwriting object3 in the cache. Once all the object creation functions are called Excel proceeds to call function() with the results of the object creation functions, each function returned the same cache key, so when xlSlim fetches the objects from the object cache it ends up getting four copies of object4 and passing this down to Python. This is why your example spreadsheet was behaving so strangely, a LateralBuckling object was created last, and then passed through to Python as the object for every parameter.

I have found a way to calculate the cache key so function and paramaters are part of the key. I've tested that this solves the problems you observed. I will release a new xlSlim version in the next day or two with these improvements.

Thanks again for the detailed example Excel file and Python code.

xlSlim Dev

unread,
Oct 24, 2024, 8:10:38 AM10/24/24
to Romain Bodson, xlSlim Support
Hi Romain,

I have released version 4.0.1 which addresses this issue. Please download the latest version from https://www.xlslim.com/pages/downloads

Thank you for reporting the issue and providing such detailed information.

Please consider buying a premium license to support future development,

All the best,
Russel


Romain Bodson

unread,
Oct 25, 2024, 8:23:21 AM10/25/24
to xlSlim Support
Thanks a lot for our help !

Yes we will do this :)

have a good day,
Romain
Reply all
Reply to author
Forward
0 new messages