Variables don't stay in 2.25

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

m.hertel
Posts: 3
Joined: Tue Nov 05, 2002 3:55 pm

Variables don't stay in 2.25

Postby m.hertel » Tue Nov 05, 2002 4:02 pm

Hello,

after upgrading from 2.23 to 2.25 scripts like
the following (linked to FrameChange) stop working:

try:
print conn
execpt:
conn = "something"

In 2.25 continuesly a exception is thrown. In 2.23
only the first time, when conn is undefined.

Any ideas?

markluffel
Posts: 13
Joined: Sun Oct 20, 2002 12:16 am
Location: Georgia Tech, Atlanta
Contact:

Postby markluffel » Wed Nov 06, 2002 8:07 am

The way I understand it, older blender keep a single python interpreter active and in the same namespace. It seems 2.25 doesn't do this. Therefore your variables are destroyed at the end of each script run.
This state will not continue for long.

m.hertel
Posts: 3
Joined: Tue Nov 05, 2002 3:55 pm

Postby m.hertel » Wed Nov 06, 2002 9:51 am

Yesterday, I tried writing a python C API Module.

For testing I've placed some printfs() in it. The Module init-Function
is only called once during Alt+A.

Maybe the variable thing is a bug?

eeshlo
Posts: 132
Joined: Wed Nov 06, 2002 10:02 pm

Postby eeshlo » Wed Nov 06, 2002 10:14 pm

m.hertel wrote:Yesterday, I tried writing a python C API Module.

For testing I've placed some printfs() in it. The Module init-Function
is only called once during Alt+A.

Maybe the variable thing is a bug?


This is not a bug. There are reasons for it, it keeps thing a lot cleaner for one. When you run a script, everything that it imports and creates doesn't go away even when starting with a new scene unless you restart Blender (Blender <= 2.23). C/C++ Extension modules are only initialized when first loaded.
If you really want to do this in Publisher you can use the same trick as the blenders gamers might use in their python scripts: make your variables attributes of the Blender module itself:

Code: Select all

import Blender

Blender.myVariable = myVariable_value


And of course myVariable can be anything, any python object. This will 'stick' untill you quit Blender, you can start with a new scene (ctrl-x) and the variable will still be available.

m.hertel
Posts: 3
Joined: Tue Nov 05, 2002 3:55 pm

Postby m.hertel » Thu Nov 07, 2002 8:08 am

That is what I want. Now my script is running with 2.25, from which I need some features.

I always was a bit apportioned about the variable stay thing.
On one side it helps keep variables through the time. On the
other side, during development there are some problemes, scripts
stop working after next start of Blender...

Making it a attribute of Blender is the much better way. I just didn't know that this is posseble (I'am quite new with python).

Thanks for help!


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests