for convenience

Avi Gross avigross at verizon.net
Mon Mar 21 17:47:56 EDT 2022


Chris,
I think you understood the context but not the premise in a sense that wasin the way Paul was thinking. His premise is way off
He seems to be thinking of something like a macro concept as iscommonly used in languages like C so:
#define context bpy.context
That could, in such languages, use a macro preprocessor, to parse the code once to make various textual changes without any real understanding of thelanguage and produce output ready for a compiler or interpreter phase. Python has nothing really like that albeit I can think of some things as well asgimmicks and tricks that can result in less typing. As an example, you canarrange for an object embedded within another to have some way to manipulate deeper structures from a higher level meaning less typing.
As you point out, in many  languages, often we are dealing with an implicit pointer withvery different results. And it is not at all the same in other ways, as you againpoint out so if you later re-assign bpy to anything else, including anotherdistinct object of the same kind, the variable called "context" keeps pointingto the old part of bpy. It is not an alias that can be used and it also is a potential problemfor various reasons such as retarding garbage collection or being used laterto make a change in the wrong place.
So, I ask Paul what other language than python he has used before, just out of curiosity.Many and perhaps most of use regulars here have used quite a few others and eachhas its own quirks and we have adjusted our thinking multiple times by the time welearned Python. What Paul suggests is just a convenience is more than that. It is a variablebinding with many ramifications.


-----Original Message-----
From: Chris Angelico <rosuav at gmail.com>
To: python-list at python.org
Sent: Mon, Mar 21, 2022 5:17 pm
Subject: Re: for convenience

On Tue, 22 Mar 2022 at 08:13, Paul St George <email at paulstgeorge.com> wrote:
>
>
> When I am writing code, I often do things like this:
>
> context = bpy.context  # convenience
>
> then whenever I need bpy.context, I only need to write context
>
>
> Here’s my question:
>
> When I forget to use the convenient shorter form
>
> why is bpy.context not interpreted as bpy.bpy.context?
>

I don't understand the question. When you do that "for convenience"
assignment, what you're doing is creating a local variable named
"context" which refers to the same thing that bpy.context does (or did
at the time of the assignment, but presumably you only do this when
bpy.context won't get reassigned). It has no effect on any other name.
There's no magic happening here - it's just assignment to the name
context, like anything else.

What are you expecting to happen here?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list