Old 12-13-2018, 09:22 AM   #1
Cedrik0s
Human being with feelings
 
Join Date: Oct 2014
Posts: 77
Default Python scope?

Hi there.

I have a rather basic question I suppose, although I can't seem to find an easy answer among the though rather thorough online information.

Say I create a file MyLib.py containing the following utility definition (for debugging purpose):

Code:
from reaper_python import * 

def dbg(m):
  RPR_ShowConsoleMsg("%s: %s" %(m, eval(m)))
  RPR_ShowConsoleMsg("\n")
If I then create another py file and call this function, then the eval is failing:

Code:
import MyLib
foo = 123
MyLib.dbg("foo")
Then I get the following error:
Code:
NameError: name 'foo' is not defined
If I define the dbg function in the py file that uses it, it works.
It's like the scope of foo is wrong when dbg is in another py file.

I am sure this is basic stuff but couldn't really find out a solution for the time I could dedicate to it...

Thanks for your help.
Cedrik0s is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:29 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.