python - Creating folders based on a list read from a text file -


i have code follows:

from sys import argv import os; home_dir = '/home/joga'   script, dirlist = argv mylist = open(dirlist, 'r') folder in mylist:         newfolder = home_dir+'/'+folder         print "folder name " +newfolder         if not os.path.exists(newfolder):                 os.makedirs(str(newfolder))         os.chdir(newfolder) mylist.close() 

the idea read list of folders listed in text file, , create each of these folders if don't exist. getting folders created, have strange names, example stray '?' appended folder name

how fix this?

answering own question

i added folder = folder.strip() first line in loop. guess line-ending creating junk character.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -