# Pythonic Question

Dear Pythonic Friends (Hehe…),

``````z= 0
for x in range (1,5):
if x is not 3:
y = x = z
z=x+2*y-100
print(y)
#print(x)
``````
``````0
-100
-400
``````
``````z= 0
for x in range (1,5):
if x is not 3:
y = x = z
z=x+2*y-100
print(y)
print(x)
``````
``````0
0
-100
-100
-400
-400
``````

Is there a way I can simply get the y and x values directly? Like…

``````0
-100
-400
0
-100
-400
``````

No debugging, please… It’s irrational for me.

What I’ve tried so far with the Python programming language is nonsense. In a nutshell, the guy who wrote Python is duping people. It’s a good thing for him because he could sit in the seat forever. I watched his interview once, and yet he didn’t (intentionally) address the core part of the language.

Anyway, back to the question…

What do you mean by ‘get directly?’

In your function x and y always have the same value.

Direct answers, such as “What is the VALUE of x and y?” Visually, it’s similar to the current push-pull operation. My eyeball has to track each line of action.

Um, it’s right there. There’s no point in X and Y even being different variables, their values are always the same.

Ugh… I will have to get used to it. Thanks!

Get used to what? What do you want the output to look like? This is a bit baffling.

I wanted this result visually.

Then just print X or Y… they’re both the same value all the time anyway, they’re actually the same variable. You expected 2 print statements per run of the loop to print one thing?

Another question: Strictly speaking, even “y” wasn’t defined. Why is it showing “Z” as undefined?

Does it make sense to you?

``````#z= 0
for x in range (1,5):
if x is not 3:
y = x = z
z=x+2*y-100
print(y)
print(x)
xy=z
print(xy)
``````
``````NameError: name 'z' is not defined
``````

However, this script works.

``````for x in range (1,5):
if x is not 3:
y = z = x
z=x+2*y-100
print(y)
print(x)
xy=z
print(xy)
``````
``````1
1
-97
2
2
-94
4
4
-88
``````

I guess order matters for “defining” things. What a stupid language!

Or, maybe I’m not advanced enough yet (of course) to understand the purpose of such irrational behaviors.

Yes it makes sense.

Saying “Y=X=Z” sets X and Y to Z. Z has no initial value in your first script. In the second you set them to X, which is defined.

How did you expect this to work? Just to assign the other 2 variables to the first it found that had a value? A=B=C is not a mathematical concept.

I’m trying to understand the logic of the Python language here, meaning I’d like to go into the inventor’s mind.

I need more time to digest… Thank you very much!

BTW, your webpage is invalid. Or, I can’t access the webpage.

“Your (my) connection is not private” - Maybe this is the issue from my side (Excuse me…)

here is what your original code means & does, step by step

``````at iteration #

0: x is 1
z is 0
set x and y to 0
set z to 0+(2*0)-100 = -100

1: x is 2
z is -100
set x and y to -100
set z to -100+(2*-100)-100 = -400

2: x is 4
z is -400
set x and y to -400
set z to -400+(2*-400)-100 = -1300

3: x is 5
z is -1300
set x and y to -1300
set z to -1300+(2*-1300)-100 = -4000

at end
x is -1300
y is -1300
z is -4000
``````

when you write y = x = z, it is like writing

``````tmp = z
y = tmp
x = tmp
``````

there is nothing irrational here, creating a language entails making design decisions

and one goal in designing a language is that it should help programmers do the right thing, so what happened in your example where z was not defined, is that python’s design says it should assume you have mistakenly used an undefined variable, and refuse to continue on in an undefined state – this is a good thing, not a bad one

Thanks; I need more time to think about many “WHYs.”

I know this is clearly bait, but please, do elaborate

Because it’s like a math language, but it’s not strictly. However, it’s also like a math language. Conceptually, they’re almost similar but not exact, like 100%.

Hmm, very deep… I think I’m too rooted in the real world to understand this sort of higher plane philosophical statement…

Speaking of real world, what is your goal here? Are you wanting to learn to script/program functions in Rhino with Python, or is this more of a theoretical investigation into the language and its structure…

From a practical standpoint, on this forum and elsewhere are thousands of scripts for Rhino written in Python which work great, not to mention the bazillions of other people using Python to program all sorts of things, so calling it “nonsense” is actually nonsense.

1 Like

Yes, because that’s how I’m oriented. RhinoPython is a long way from where I am now, but I have some theories (nothing serious, just personal interests as a hobby) about how to combine everything.

“Nonsense” is based on mathLang (?); it’s subjective as well, as everyone’s mind is his or her own universe.

I also believe that this universe is “what you and I defined.”

This might illuminate things:

1 Like

I guess almost every programming language then is stupid.

And to be honest, that is how people work too. If you don’t define a new concept in a discussion, but leave it up to imagination, you’ll get essentially undefined behavior. Unexpected results from what you were intending. People not understanding what you are trying to say.

1 Like