A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/306541.html below:

batch mkdir using a file list

batch mkdir using a file list batch mkdir using a file listPeter Otten __peter__ at web.de
Fri Sep 23 16:11:03 EDT 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()
    os.mkdir(directory)

Peter


More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4