converting list of list to a string gives "none" values

I'm writing a scraper and I'm creating a list of list and want to store in the text file as a string in every iteration of the outer loop like I've

all_products_ids = ['1','2','3']
outer_pro_list = []
product_data = ['data1','data2']
for pro_id in all_products_ids:
    inner_product_list = []
    for prod_data in product_data:
        inner_product_list.append(str(prod_data))
        print("Apending")
        outer_pro_list.append(inner_product_list)
        with open('myfile.txt', 'w') as f:
             f.write(str(outer_pro_list.append(inner_product_list)))

what I'm looking in the output is list of list like below without removing "[" "]" in the text file

[[data1,data2],[data1,data2]]

`

Upvotes: 1

Views: 95

Answers (1)

Kenny Ostrom
Kenny Ostrom

Reputation: 5871

You are not writing what you think you are writing, because list.append does not return a value.

A simplified version of the issue, for illustration.

data = []
print ("This is what you are writing:")
for n in range(6):
    print (data.append(n))
    
print ("This is the data you didn't print:")
print (data)

Upvotes: 1

Related Questions