Search code examples
pythonzapier

Extract data in between characters within string in Zapier using python


I am working to extract the twitter handle of a user from a string of text.

The text is always in this format:

SomeText (@handle)

BTW, I am running this as a step in a multi-step zap. My idea was to use python to extract everything in between the parenthesis using this code:

s = input_data['s']
return s[s.find("(")+1:s.find(")")]

I defined s in my zap per the documentation, see screen shot:

enter image description here

I am getting the following error:

'str' object has no attribute 'copy'


Solution

  • Your issue is that data returned from a Python Code step must be JSON serializable.

    try this:

    s = input_data['s']
    return {'handle': s[s.find("(")+1:s.find(")")]}