Hi there,
I’m transplating an app that I was writing in JS but I’m not really a developer so thought I’d try it in Anvil instead.
I’m using a loop to calculate capacity figures over a number of days which are appended to a list. The problem is that at the end of the loop the list only has one entry.
I’ve tried other loops in the same module with no issue, just the main loop appears to have the problem.
https://anvil.works/build#clone:YL3ROOC7UKI6GA6N=YBYG25SFUUANXT5I2GRHAREH
The line in question is in ‘LoopModule’ line 107. There is quite a bit going on in there so let me know if want any info.
Thanks,
Ed
Hello,
What are the steps to reproduce the error?
If you uncomment the:
if day == scopeDays:
print(day)
print(len(dailyStorageArr))
You’ll see that the length of the list (I’m calling it arr in the name as I’m transplating from JS) is 0 and not the 365 it should be (based on 1 year in the form).
I don’t know where those lines are though. If they are commented out, will this lead to line 107 getting the error? I’m trying to help but you’ll have to guide me through with more specific steps. So far I know the line it crashes on, but not how to make it crash there.
it’s not crashing, just having an issue getting the list to append, it’s probably a Python noob thing (actually I’m fairly certain). Maybe a scope thing?
That code is on lines 186-188 in the LoopModule component. You’ll see that it’ll print the length of that list which will be zero.
Okay, now which steps do I run to get it to hit that code?
Just add the date to the form and press the ‘run calculation’ button.
Just having a cursory look, but you have a line in the while loop that says:
dailyStorageArr.pop(0)
This will remove the first item from that list. If this is hit every time through the loop, the list will never have more than one item. If I remove that line, the list accumulates and crashes somewhere else later on.
I hope this helps you to make progress as you debug.
3 Likes
Got it, the ‘dailies’ aren’t being set so that if statement is running which as you say stopping the array from being filled. I’ll have to figure out why that’s happening.
1 Like