Forum Archive

Own Python Modules?

metawops

It's not possible to write Python scripts in Editorial's editor.
So if I need to write a module and import it in a Python action in a workflow – how would I achieve this?
Please don't let the answer be "You cant!"

Thanks so much,
Stefan.

TutorialDoctor

There is a "Run Python Script" action in the action presets. You can export the entire script to the next action if you want to (no syntax correction in the editor.)

I have a workflow called "Modular Python" that let's you use actions as independent scripts.

What is it exactly you want? I'm sure it's possible.

Helgi

You can place a .py module in Editorial's Local Storage, and then import it from inside a Run Python Script action. This works, but is cumbersome:

  1. You can't edit a Python file stored in Local Storage. You have to create a .txt file, then rename it to .py with the help of a custom workflow.
  2. If you want to edit this module, you have to repeat the edit-as-txt / rename loop over and over. If you have a ready-to-use module already, this might work for you.

As for me, I wanted to be able to share some code that is common to a number of workflows. Say, one workflow uploads a post to my blog, and another one downloads a post, updating an Editorial document. Obviously I'd like to share the upload/download code, but the approach I described doesn't work as I want to iterate on my upload/download module.

I wish there was a shared storage of Custom Actions, so if I edited the code of a Custom Action in one workflow, all other workflows having the same Custom Action would receive the updated copy of the script. As far as I understand, this is not the case.

Does anyone happen to have any ideas regarding this? I just really hate Copy & Paste for code.

ccc

> It's not possible to write Python scripts in Editorial's editor.

It is now.

It seemed like an interesting problem so I created two workflows: Save as Python... and Edit Python... to assist in the creation and editing of Python files that you can import your own Python scripts into your Editorial workflows.

You can use Save to Python... to put my_script.py into place and then your "Run Python Script" task would be:

#coding: utf-8
import my_script, workflow
workflow.set_output(my_script.main(workflow.get_input()))

If you are editing Python files then you might want to force a reload to ensure your workflow is really importing your latest and greatest code:

import my_module_a  ;  reload(my_module_a)
import my_module_b  ;  reload(my_module_b)