0

I am trying to write my_list to a csv file like below:

import csv

myfile = open('my_list.csv', 'w')
wr = csv.writer(myfile)
print(len(my_list))
wr.writerow(my_list)

my_list has length 1000. Then the output of the above code is:

1000
10001

The output my_list.csv looks fine. But I am wondering why it print out 10001 on the screen? What does it mean?

1 Answer 1

2

It looks like you are doing this in the Python console. When you print len(my_list), it will print 1000. Next, you use wr.writerow(). It will write the row to the file and then return the current position in the file. Since it just wrote 1000 lines, the file position is at 1001 so that the next line written will not overwrite anything. In the Python console, the value that is returned is printed. If you were to execute a file with the same script, you wouldn't see that number.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.