0 votes

In Dataiku, the functions defined in the project library do not have access to the global variables. This becomes a problem when we create global objects such as sparkContext and SQLContext. Is there a way to fix this?

For example, I created two identical functions, one placed in a library module (ca.py) and one placed in the main program (Main.py).

Calling x=getglobal() will run without a problem. However, when calling y=getglobal2() it will throw an error saying: "global name 'GVarX' is not defined.

ca.py:

def getglobal2():
    return(GVarX)

Main.py:

import ca

global GVarX
GVarX=1

def getglobal():
    return(GVarX)

x=getglobal()
y=ca.getglobal2()

 

asked by

1 Answer

0 votes
Hi,

In Python, Globals are global to a module, not across modules. You'd be better off avoiding globals by creating a class in ca.py with attibute GVarX and assign a value to it in your main.py module

Best,

Jean-Yves
answered by
944 questions
978 answers
989 comments
2,153 users

┬ęDataiku 2012-2018 - Privacy Policy