无法更改目录

时间:2019-07-28 19:47:14

标签: python powershell directory

我对编码非常陌生,并且正处于“学习Python 3的艰难方法”一书的开头。

这本书告诉我去Powershell并键入override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell if indexPath.section == 0 { cell = tableView.dequeueReusableCell(withIdentifier: "workspace", for: indexPath) if indexPath.row == addWorkspaceRow { cell.imageView?.image = .addWorkspace cell.imageView?.tintColor = cell.tintColor cell.textLabel?.text = "Add Workspace" cell.textLabel?.textColor = cell.tintColor cell.accessoryType = .none } else { let workspace = model.workspaces[indexPath.row] cell.imageView?.image = .workspace cell.imageView?.tintColor = .label cell.textLabel?.text = workspace.displayName cell.textLabel?.textColor = .label cell.accessoryType = .disclosureIndicator } } else { cell = tableView.dequeueReusableCell(withIdentifier: "archive", for: indexPath) cell.imageView?.image = .archive cell.imageView?.tintColor = .archive cell.textLabel?.text = "Archive" cell.textLabel?.textColor = .label cell.accessoryType = .disclosureIndicator } cell.textLabel?.font = .preferredFont(forTextStyle: .body) return cell } ,以便它将运行ex1.py,但是如果我这样做,它会说

python ex1.py

经过研究,我发现需要将目录更改为lpthw,即C:\Users\Olga\AppData\Local\Programs\Python\Python37-32\python.exe: can't open file 'ex1.py': [Errno 2] No such file or directory PS C:\Windows\system32\WindowsPowerShell\v1.0> 所在的位置。

因此,我正在尝试更改目录以打开ex1.py,当我键入cd lpthw时,它不会将目录更改为lpthw,即

ex1.py

但是相反,它将lpthw附加到powershell所在的目录中,所以它告诉我

C:\Windows\System32\lpthw

我在网上找到了一个答案,说要键入python和一个空格,然后将ex1.py拖到Powershell中,但这又给了我

PS C:\Windows\system32\WindowsPowerShell\v1.0> cd lpthw
cd : Cannot find path 'C:\Windows\system32\WindowsPowerShell\v1.0\lpthw' because it does not exist.
At line:1 char:1
+ cd lpthw
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Windows\syst...hell\v1.0\lpthw:String) [Set-Location], ItemNotFoundE   xception
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32\WindowsPowerShell\v1.0>

Soooo ...如何让它运行ex1.py?

谢谢!!!!

1 个答案:

答案 0 :(得分:0)

这令人沮丧,但是您会习惯的!

  

当我键入cd lpthw时,它不会将目录更改为lpthw,而是将lpthw附加到powershell所在的目录中

这些目录名称是用于描述计算机中某些物品的地址。在每个\处,右边的事物在左边的事物之内。如果您的路径以左侧的C:开头,经过许多目录,最后以您要使用的位置或文件结尾,则这是完整路径而且您可以在任何地方使用它,因为它描述了一个完整的位置,没有混乱的空间。

相反,如果仅使用“ lpthw”之类的短路径,则称为相对路径,它描述了如何从当前目录开始到达某个地方。

相对路径更短,更方便,但可能会造成混淆,因为它们的位置随着您走动而改变。全路径更费力,但更精确。

这非常接近:

python C:\Windows\System32\lpthw\ex1.py\

右侧的\表示ex1.py是目录,我认为这是您的问题。删除它,所以它说:

python C:\Windows\System32\lpthw\ex1.py

我认为这可能有用。

这应该行得通,但是正如Lee_Dailey所说, 是一个奇怪的地方。 C:\Windows\System32中的任何内容最好都留给Windows管理。在某个时候,尝试找到一种方法将整个C:\Windows\System32\lpthw\文件夹移到您的文档中,例如C:\Users\Olga\Documents\lpthw\

相关问题