Grasshopper

algorithmic modeling for Rhino

Hi,

I've been making a python script and noticed something that is funny that I don't recall happening previously.

Essentially, I define a variable and print(variable)

numbers = [1,2,3,4]

print(numbers)

hitting F5 returns

[1, 2, 3, 4, 5]

so I comment out the variable definition

#numbers = [1,2,3,4]

print(numbers)

hitting F5 still returns

[1, 2, 3, 4, 5]

This is making code editing really difficult, since I am using print to check values and I cannot trust what comes from it. I have a much larger script which is suffering the same situation:

(after hitting F5 and [Test] repeatedly)

Is this a bug or am I using this wrong. I swear I've never noticed this before.

Thanks,

Shane

Views: 580

Replies to This Discussion

Hi Shane

the variable name 'numbers' is still linked to the list object [1, 2, 3, 4, 5], to change this behavior you've got to reassign the whole variables in the comment block to none, this behaviour happens because the garbage collection isn't called untill the python code is closed, so the memory is freed, but as long as this code lingers in th GHPython component the list object is still retained in your RAM,

maybe one way to get around this is to copy/past [along with the componenets linking to this code as parameters] the GHpython component and delete the older one

that shouldn't print the comments block anymore

Ah, that makes sense then. Thought I was going nuts. I have done a number of python scripts in GH, but I guess I never noticed until now.

We've discussed this subject quite extensively over on the GHPython GitHub repo. As always Giulio makes it all make perfect sense by the end :)

Link(writing on an iPad): https://github.com/mcneel/ghpython/issues/53

As Anders mentions, we discussed this publicly and came to a slight change in behavior. This change is already implemented in the Rhino WIP. At this point, this will likely stay as it is in GhPython for Grasshopper 0.9.76.

Essentially, the variable will still stick around, because it is useful, when Grasshopper or the user re-runs the script; however, when the user clicks the 'Run/Test' button in Rhino WIP, the editor will remove all variables as though the script was run in a new scope for the first time. This will make finding bugs simpler, while at the same time allow to keep track of 'counters' and sticky variables.

I hope this explains the case. Thanks,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

I see, I guess I was used to using the component as a substitute IDE but had miraculously never noticed this behavior before. Good to know, thanks!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service