Created
July 21, 2018 18:07
-
-
Save andypetrella/6f3df40034aad48591d7f28d1c7697ff to your computer and use it in GitHub Desktop.
How to reference a scala object in python using Py4j (JavaGateway)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This function takes the fully classified object name, say: <package>.<name>. | |
# Returns the static object instance on the heap | |
def ref_scala_object(object_name): | |
clazz = jvm.java.lang.Class.forName(object_name+"$") | |
ff = clazz.getDeclaredField("MODULE$") | |
o = ff.get(None) | |
return o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala_none = ref_scala_object("scala.None") | |
scala_none.getClass().getName() # returns 'scala.None$' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment