I am currently new with coding in Python with CSV files, and need help with the following code:
import csv
import random
# Initialize an empty list to store the CSV variables
CSVars = []
# Read the CSV file
with open('greeting.csv', 'r') as f:
reader = csv.reader(f)
for _ in range(16): # Assuming there are 16 rows in the CSV
CSVars.append(next(reader))
print(random.choice(CSVars))
Basically, in this code, I get a random value from a file called 'greeting.csv'. However, whenever I get a value, it is always in this format -> '[value]'. Does anyone know to strip it and make it -> value?
I tried to append it to a list in different ways, but do not know how to 'strip it'.