Python basic questions (related to csv file output)

Asked 2 years ago, Updated 2 years ago, 82 views

There's a difficulty with the chords that I've never learned before. I felt like a wall to ask questions. I'm leaving a message because I have something to ask while I couldn't find a place to ask. I tried to create a random number and name in one line of the csv file and put 100 in it.

The file prints well If you put a variable in the wr.writerow, [1] and [kim] are created like this If you put more than one variable, [1,5,3] and [kim, park, park] will work like this.

Even if it's too basic, please. Please, look at Newbie with pity.

----------------------------------------------------

import csv
import random


stList = [1,2,3,4,5,6,7,8,9]
naList = ['kim','lee','park']
f = open('mkname.csv','w')
wr = csv.writer(f)

num=100
for i in range(0,num):
    stL = random.sample(stList, 1)
    naL = random.sample(naList,1)
    wr.writerow([stL+stL+stL,naL+stL])




f.close()

python csv

2022-09-20 21:51

1 Answers

It was simple to receive it as a text file, not a csv file.

I don't want to delete it because it's my first question, so I'm answering it myself. If you don't have the basics because you learned it like me, I think New B will be able to see the same question.


2022-09-20 21:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.