Parsing CSV files in C#, with header

A CSV parser is now a part of .NET Framework. Add a reference to Microsoft.VisualBasic.dll (works fine in C#, don’t mind the name) using (TextFieldParser parser = new TextFieldParser(@”c:\temp\test.csv”)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(“,”); while (!parser.EndOfData) { //Process row string[] fields = parser.ReadFields(); foreach (string field in fields) { //TODO: Process field } } } … Read more

A non-blocking read on a subprocess.PIPE in Python

fcntl, select, asyncproc won’t help in this case. A reliable way to read a stream without blocking regardless of operating system is to use Queue.get_nowait(): import sys from subprocess import PIPE, Popen from threading import Thread try: from queue import Queue, Empty except ImportError: from Queue import Queue, Empty # python 2.x ON_POSIX = ‘posix’ … Read more