Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Python f-string CSV output list formating

So I have a simple CSV file with a few fields that appear like this:

image1, left
image2, right
image3, left

I am trying to extract the image names and add them to a string with this bit here:

templateImages = []
html_output = ''

with open('temp1.csv', 'r') as data_file:
    csv_data = csv.reader(data_file)

    for line in csv_data:
        if line[0] == '':
            break
        templateImages.append(f"{line[0]}")

        html_output += f"\n{{% assign template_image = 'https://www.website.com/image/{templateImages}' %}}"

print(html_output)

This give me an output of:

{% assign template_image = 'https://www.website.com/image/['image1']' %}
{% assign template_image = 'https://www.website.com/image/['image1', 'image2']' %}
{% assign template_image = 'https://www.website.com/image/['image1', 'image2', 'image3']' %}

However I am trying to format it in a way to list a single image per url, and without it's brackets and quotes like so:

{% assign template_image = 'https://www.website.com/image/image1' %}
{% assign template_image = 'https://www.website.com/image/image2' %}
{% assign template_image = 'https://www.website.com/image/image3' %}

I've dug around Stack Overflow for quite a few days but haven't been able to pinpoint where I need to start. Does anyone have any advice?

Comments