[python-events] I find a bug of python
李远志
893432077 at qq.com
Thu Jun 14 04:47:29 EDT 2018
hello , when you run this code:
import csv
csvFile = open('mycve.csv','r')
csv_reader = csv.reader(csvFile)
print list(csv_reader )
print list(csv_reader )
you will find that first 'print' can print the content of mucve.csv successfully , but the second print will print an empty list
when I try to solve this question , I find that csv_reader's line_num variable is the length of mycve.csv after first print function.
so when I start the second print , I will get an empty list
I try to solve like this after first print :
csv_reader.line_num = 0
but it's a readonly attribute.
I know when we programming , we can solve this bug like this :
a = list(csv_reader)
print a
print a
but when we want to use csv_reader again , we will get an empty list,maybe some people will doubt when they code like this:
a = list(csv_reader)
b = list(csv_reader)
why 'b' is empty!!?
this is a little bug of python,but I hope you can solve this ,wish python better and better
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-events/attachments/20180614/b7ae0283/attachment.html>
More information about the python-events
mailing list