Newbie question about Python syntax

Paul St George email at paulstgeorge.com
Sat Aug 24 15:52:21 EDT 2019


On 24/08/2019 01:23, Cameron Simpson wrote:
> On 23Aug2019 13:49, Paul St George <email at paulstgeorge.com> wrote:
>> Context:
>> I am using Python to interrogate the value of some thing in Blender 
>> (just as someone else might want to use Python to look at an email in 
>> a Mail program or an image in Photoshop).
>>
>> Assumptions:
>> So, I want to look at the attribute of an instance of a class called 
>> CompositorNodeMapValue. The code in the Python tutorial seems to be 
>> for creating an instance of a class, but I assume Blender (in my case) 
>> has already created the instance that I want to interrogate.
> 
> That would be the expectation. And to interrogate it, you need that 
> instance to hand in a variable.
> 
>> Question:
>> If this is so, should I find the code to get a list of the instances 
>> that have been made (maybe using inspect?) and then, when I have its 
>> name, the attributes of the one that interests me?
> 
> Have you not got one of these handed to you from something?
> 
> Or are you right at the outside with some "opaque" blender handle or 
> something? (Disclaimer: I've never used Blender.)

Thank you once again.
If I understand your question, I am right outside. By this I mean I have 
not created anything with Python. I have made the Blender model with the 
UI and am trying to use Python to read the values for the settings used. 
This has worked for all settings except this Map Value Node.

> 
> You can inspect objects with the inspect module. You can also be more 
> direct. Given an object "o", you can do an assortment of things:

Before I do any of the following, I assume I need to use something like:

import struct
class CompositorNodeMapValue(o):

I have tried this. Nothing happens. Not even an error. It's like waiting 
for Godot.

I am guessing I am in the wrong namespace.

I don't know whether it is relevant, but I tried plain
dir()
and
dir(struct)

They each returned a list and neither list had mention of 
CompositorNodeMapValue

If I do something like:
o = CompositorNodeMapValue()
I get:
NameError: name 'CompositorNodeMapValue' is not defined

> 
> dir(o) gets a list of its attribute names.
> 
> help(o) prints out the docstring, somewhat rendered.
> 
> o.__dict__ is usually a dict mapping attribute names to their values.
> 
> type(o) gets you its type, so "print(type(o))" or 
> "print(type(o).__name__)" can be handy.
> 
> A crude probe function (untested):
> 
>   def probe(o):
>     print(o)
>     for attr, value in sorted(o.__dict__.items()):
>       print(" ", attr, type(value).__name__, value)
> 
> Enjoy,
> Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)
> 
> "Are we alpinists, or are we tourists" followed by "tourists! tourists!"
>         - Kobus Barnard <kobus at cs.sfu.ca> in rec.climbing,
>           on things he's heard firsthand





More information about the Python-list mailing list