0
I am new here, I am very beginner in programming and I am starting with Python. I am in a personal project that is well advanced but I am with a very specific difficulty, I want to write in a CSV file only a desired number of lines. This command below generates a giant file many times with more than 30k rows of data but by system demonstration I want to write only 50 rows of data in the file;
with open("arquivo.csv","w",encoding='UTF-8') as f:#Enter your file name.
writer = csv.writer(f,delimiter=",",lineterminator="\n")
writer.writerow(['username','user id','name','group'])
for user in all_participants:
if user.username:
username= user.username
else:
username= ""
if user.first_name:
first_name= user.first_name
else:
first_name= ""
if user.last_name:
last_name= user.last_name
else:
last_name= ""
name= (first_name + ' ' + last_name).strip()
writer.writerow([username,user.id,name,target_group.title])
How can I limit the amount of recorded information:
They told me to use the function enumerator but I’m getting it, I’m too green still kkk
Thanks for the help!
I recommend reading the documentation available in the link below. It demonstrates examples of counters within loop(s) and execution flow control instructions within a loop with instruction
for
. https://answall.com/questions/322/qual-a-diferen%C3%A7a-entre-break-pass-e-continue-em-python– siga0984