使用截断报价处理CSV

时间:2017-06-17 00:06:54

标签: python csv

所以我在csv中有一些带有delimiter =''和quotechar =''的数据。我正在使用python csv包来读取它,但这里是捕获。有一行在报价中有一些文字,或者只是一个单独的引用,它看起来像这样

...
"
...

或者像这样

import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;

public class MainClass {

    static int numOfIterations = 100;

    static AtomicInteger numOfOperationsDone = new AtomicInteger(0);
    static ArrayList<Long> clientOperationTimes = new ArrayList<>();
    static ClientThread[] clientThreads; 
    static int numOfClients = 1;

    static long timeBeforeExp = 1000;
    static long expDuration = 3000;

    static boolean record = false; 
    static boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        clientThreads = new ClientThread[numOfClients];
        Thread[] threads = new Thread[numOfClients];
        for (int i=0; i< numOfClients; i++){
            clientThreads[i] = new ClientThread();
            Thread t = new Thread(clientThreads[i]);
            threads[i] = t; 
        }
        for (int i=0; i< numOfClients; i++){
            threads[i].start();
        }

        Thread.sleep(timeBeforeExp);

        record = true;


        long start = System.nanoTime();
        Thread.sleep(expDuration);
        stop = true;
        record = false;

        long elapsed = System.nanoTime() - start; 

        System.out.println("Actual elapsed time= " + Math.pow(10, -6) * elapsed);

        double throughput = Math.pow(10, 6)*numOfOperationsDone.longValue() / (double)elapsed;  
        System.out.println("Throughput= " + throughput);

    }

}

有什么方法可以告诉读者如果它遇到换行符就结束引用?

1 个答案:

答案 0 :(得分:0)

如果读者可以处理这样的行,例如: 假设10列

if len(csv_list) < 10:
    # Skip or repair Data