在这种情况下,你不能使用默认的quotechar,它是",因为 CSV 数据中已经包含了这个字符,所以要指示 CSV 读取器输出时将"John"包含在内,你需要指定其他的quotechar,可以是|、;或任何符合要求的字符。 现在输出中包括带引号的John和Tom。 ['Hello', 'My', 'name', 'is', '"John"'] ['Hello', 'My', 'nam...
This is the expected behavior for the default CSV dialect. Spaces are considered to be part of the field and are not ignored. You can set Dialect.skipinitialspace to True to change this behavior. In the future, it's a good idea to ask about potential bugs on https://discuss.python.org...
明确设置quotechar参数:在调用相关函数(如csv.reader、csv.writer或pandas.read_csv等)时,确保在启用引用的情况下明确设置quotechar参数。 python import csv # 正确的设置方式 with open('example.csv', 'r', newline='') as csvfile: reader = csv.reader(csvfile, quoting=csv.QUOTE_ALL, quotechar='"')...