How to get raw code content of another python script

@piac

Is there a way for a python script to get the raw code from another python script?
Similar to how GhPython.Assemblies.CodeGeneration.GenerateComponentCode works?

The output should be a raw string, newlines will be \n etc.

Hello,

If you wrap the other script in a function then you can get it using inspect.getsource(my_function)

1 Like

Thanks!
Just wondering how to use this?
would it be:

component = doc.documentId
inspect.getsource(component.functionName)

I just realised the inspect() is usually used to inspect a module, but what if it was to inspect another component?

After looking at the dir(ZUIPythonComponent ), the solution is really obvious.

code = ghpython_script_component.Code

2 Likes