Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5875

Affecting input vs producing output

$
0
0

@lawrenceyy wrote:

I have always wondered about this so I thought I would ask the forum.

1- How do you know when a command changes the input as opposed to producing an output? I usually expect an output:

temp1=[5,2,3,4,1]
temp2=sorted(temp1)
#temp1: [5,2,3,4,1] unchanged
#temp2: [1,2,3,4,5] produced sorted version of temp1

But then there are situations like this:

import random
temp1=[5,2,3,4,1]
temp2=random.shuffle(temp1)
#temp1: [4,3,2,1,5] shuffled
#temp2= Null, no output from shuffle

2- I feel like I've been in a situation where if you do temp2=temp1 and then proceed to change temp2, temp1 is also affected (this usually seems to happen with rhinocommon geometry- I script with GhPython). Why does this happen? I think I fixed it by doing something like temp2=temp1.duplicate() , assuming that temp1 is a rhino geometry. Is it good practice to always duplicate, even if it is a list of numbers?

Posts: 7

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 5875

Trending Articles