Python reading whitespace-separated file lines as separate lines

后端 未结 6 791
野性不改
野性不改 2021-01-25 14:18

This is on Windows Server 2008 R2. I have a file of inputs, one input per line. Some of the inputs have spaces in them. I\'m trying to use the below simple code, but it separate

6条回答
  •  执念已碎
    2021-01-25 14:48

    Without sample input it is hard to be sure, but it looks like you need to quote the directory creation.

    for line in f:
        os.system("mkdir '%s'" % line.strip())
    

    On Windows, the single quotes will cause undesirable effects, so using double quotes is probably necessary.

    for line in f:
        os.system('mkdir "%s"' % line.strip())
    

提交回复
热议问题