Q: Python Globals

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 01:45, xxxxxxxx wrote:

If I want something in say - a mograph effector to run once

can I make a global ??
without assigning a value (as it would zero each time the script ran if I did)

The correct syntax and logic would be really helpful and I'm unsure of both - pls

the sort of thing I was trying to do........have no idea how to do this correctly
advice pls

if global ------called Flag_something_done---- not assigned  : ?????
Do the operation
Flag_something_done = 1

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 05:40, xxxxxxxx wrote:

is_done = False  
  
def main() :  
  global is_done  
  if not is_done:  
      # make it done ...  
      is_done = True

But setting globals is IMHO not a good style. I prefer using mutable objects available from the global-scope.

data = type('', (), dict(is_done = False))()  
  
def main() :  
  if not data.is_done:  
      # make it done ...  
      data.is_done = True

Originally posted by xxxxxxxx

if global ------called Flag_something_done---- not assigned  : ?????
Do the operation
Flag_something_done = 1

If you really want to make it dirty:

def main() :  
  if not globals().get('is_done', False) :  
      # make it done ...  
      globals()['is_done'] = True

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 03/02/2012 at 06:46, xxxxxxxx wrote:

:)
cheers Niklas

I prefer to keep things as correct as possible
I like the idea behind the mutable object with global scope

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 05/02/2012 at 03:29, xxxxxxxx wrote:

Thanks for the info Niklas

And yes it works - but...

As far as the Python Effector is concerned
it appears this method can't be used
as the global is only set when the file is opened and first run

For the Effector
it needs something that can process

'is this the same as the last past through'?
if True - skip setting it

and its also unclear if the effector in Parameter mode
is working differently from the effector in Full mode
Can the same method be used for both

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 05/02/2012 at 09:31, xxxxxxxx wrote:

Could you please post what you have tried?

Cheers,
Niklas