returns: global name 'main' is not defined ... in getdoc func = getattr(main, func)
My VBA code is:
Function xl_GetDoc(Func As String)
Dim methods As Variant, result As Variant, Rtn As Variant
Const Modname As String = "xlAlgLib"
On Error GoTo rtnerr
Set methods = PyModule(Modname, AddPath:=Path1)
Set result = PyCall(methods, "getdoc", PyTuple(Func))
Rtn = PyVar(result)
xl_GetDoc = Rtn
Exit Function
rtnerr:
xl_GetDoc = Err.Description
End Function
Any ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
are you sure that main is always defined in python? I believe that main is actually a special module which is the top-level script, i.e. the one that python is run with. ExcelPython doesn't have this concept since you are not running a single script.
If you are trying to get a docstring from a function defined in the same module all you need to do is get it from the globals or eval it: eval("myFunction").doc
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
are you sure that main is always defined in python? I believe that main is actually a special module which is the top-level script, i.e.
the one that python is run with. ExcelPython doesn't have this concept,
because it is a script which gets executed.
If you are trying to get a docstring from a function defined in the same
module all you need to do is get it from the globals or eval it:
eval("myFunction").doc
I have a couple of functions that use getattr() to return a function object, given the function module and name. For instance:
These work fine if the function is in a different module, but if it is in the same module and I use __main__\ I get an error. For instance:
returns: global name 'main' is not defined ... in getdoc func = getattr(main, func)
My VBA code is:
Any ideas?
are you sure that main is always defined in python? I believe that main is actually a special module which is the top-level script, i.e. the one that python is run with. ExcelPython doesn't have this concept since you are not running a single script.
If you are trying to get a docstring from a function defined in the same module all you need to do is get it from the globals or
eval
it: eval("myFunction").docare you sure that main is always defined in python? I believe that
main is actually a special module which is the top-level script, i.e.
the one that python is run with. ExcelPython doesn't have this concept,
because it is a script which gets executed.
If you are trying to get a docstring from a function defined in the same
module all you need to do is get it from the globals or
eval
it:eval("myFunction").doc