在Python中获取文件复制的输入

时间:2018-10-09 16:02:05

标签: windows python-2.7

我正在尝试制作一个简单的Python工具,用于将所有内容从驱动器x复制到驱动器y,并在其中询问用户源驱动器和目标驱动器是什么。 当我从Visual Studio内部运行它时,效果很好,但是当我尝试通过命令行(python.exe pythonapplication1.py)运行它时,在输出中出现此错误:

What is your source drive letter?f

Traceback (most recent call last):
File "pythonapplication1.py", line 7, in <module>
inputSrc = input("What is your source drive letter?")
File "<string>", line 1, in <module>
NameError: name 'f' is not defined

这是该程序的代码:

import os
import sys

inputSrc ="x"
inputDest = "y"

inputSrc = input("What is your source drive 
letter?")
inputDest = input("What is the destination drive 
letter?")

src = inputSrc + ": "
dest = inputDest + ": "

copyCommand = "xcopy " + src + dest + "/s"

os.system(copyCommand)

loopCheck = "no"

while loopCheck == "no":
questionTest = input("Want to make another copy? y/n ")
if questionTest == "y":

    input("Press any key once you put in the new blank drive.")
    os.system(copyCommand)
if questionTest == "n":
   loopCheck = "yes"

2 个答案:

答案 0 :(得分:0)

您可以使用Expand-Archive -LiteralPath "Path to the archive" -DestinationPath "Extraction Path" 代替raw_input()

input()

将起作用。

答案 1 :(得分:0)

您应该在Python2中使用raw_input("question...")而不是input("question...")。这是因为input将接受用户输入并执行它。这就是为什么口译员抱怨不知道f