jeudi 24 septembre 2020

How do i select a random cell in a csv

I have a CSV file that is random words only. No header.

For example:

"dawn","go","test","these","swung" "joy","frequently","seven","congress"

My code does not select a random cell and returns the error: 'TypeError: '_csv.reader' object is not subscriptable'

My code is:

    def random_select(self):

        csv_reader = csv.reader("randomwords.csv")       
        words = list(csv_reader)
        random_names = random.choice(words)
        readcsv = csv_reader[random_names][random_names]

        print(''.join(readcsv))



Aucun commentaire:

Enregistrer un commentaire