Skip to main content
Best answer

help with python code to split data


ynnklo99

Hey guys!

I really need your help since my programming skills aren't that great and Chat-GPT isn't a great help either.

I have the input data, which is basically just a bunch of emails divided by a comma. The goal is to write each email in a separate line, so I can access them in a later step in the Zap. 

The Split option in the formatter doesn’t work at all so I thought about programming it myself.

But I don't know how I have to write the code so python recognizes the email adresses. The adresses aren't static.

Can anybody help?

 

 

Best answer by Troy TessaloneBest answer by Troy Tessalone

@ynnklo99

Try this JavaScript Code, generated with the help of ChatGPT.

let Emails = inputData.Emails.split(',');

let emailObject = {};

Emails.forEach((email, index) => {
  const propName = `email${index + 1}`;
  emailObject[propName] = email;
});

output = [{Emails, emailObject}];

 

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

Troy Tessalone
Forum|alt.badge.img+14

Hi @ynnklo99 

Good question.

Can you clarify about the desired output you want for the email addresses by providing an example of the input vs output?

 

Some options to try…

Formatter > Text > Split

 

Formatter > Text > Replace

 

Formatter > Utilities > Line Items to Text

 


ynnklo99
  • Author
  • New
  • 2 replies
  • July 13, 2023

hey @Troy Tessalone thank you for the fast reply!

the input is: loremipsum@loremipsum.de,loremipsum@loremipsum.de

the output should be:

loremipsum@loremipsum.de

loremipsum@loremipsum.de

so I can access each adress later on.

The split action seems to be buggy but idk. It seems that it separated the two adresses, but later on they are again together with a comma.

The replace action I guess you replace the comma with a line break but idk how

The utlities action does not work at all.

 


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 31416 replies
  • Answer
  • July 13, 2023

@ynnklo99

Try this JavaScript Code, generated with the help of ChatGPT.

let Emails = inputData.Emails.split(',');

let emailObject = {};

Emails.forEach((email, index) => {
  const propName = `email${index + 1}`;
  emailObject[propName] = email;
});

output = [{Emails, emailObject}];

 

 


ynnklo99
  • Author
  • New
  • 2 replies
  • July 13, 2023

@Troy Tessalone wow, thank u so much!

 


AmiriJrue
ynnklo99 wrote:

Hey guys!

I really need  circular font your help since my programming skills aren't that great and Chat-GPT isn't a great help either.

I have the input data, which is basically just a bunch of emails divided by a comma. The goal is to write each email in a separate line, so I can access them in a later step in the Zap. 

The Split option in the formatter doesn’t work at all so I thought about programming it myself.

But I don't know how I have to write the code so python recognizes the email adresses. The adresses aren't static.

Can anybody help?

 

 

You can achieve this by using the split() method and specifying the comma (",") as the delimiter. Here's an example code snippet:

input_data = "email1@example.com, email2@example.com, email3@example.com" # Split the input data into a list of email addresses emails = input_data.split(", ") # Print each email address on a separate line for email in emails: print(email)

In this code, input_data represents your input string containing the email addresses. The split(", ") method is used to split the string into a list of email addresses, assuming that the email addresses are separated by a comma followed by a space.

You can replace the print(email) statement with your desired action, such as storing the email addresses in a variable, writing them to a file, or passing them to the subsequent steps in your Zap.