batch mkdir using a file list

Peter Otten __peter__ at
Fri Sep 23 22:11:03 CEST 2005

DataSmash wrote:

> I am using bash shell on windows and I'm getting the error:
> TypeError: loop over non-sequence

Use open(filename).readlines() instead of open(filename) or switch to a
current Python version.

> OR...if python can't handle this type of text file,
> what do I need to do to remove the "\n"  from the file?

line.strip() removes all leading and trailing whitespace (not just "\n")
from the line string.

import os
for line in open("list.txt").readlines():
    directory = line.strip()


More information about the Python-list mailing list