try fileinput instead of stdin directly because I think it buffers...