我对编码非常陌生,我正在读《艰苦地学习python3》一书的开头。你知道吗
这本书告诉我去Powershell并键入python ex1.py
,这样它将运行ex1.py,但是如果我这样做,它会说
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>
经过一番研究,我有了这样的想法:我需要将目录更改为lpthw,这就是ex1.py
所在的位置。你知道吗
所以,我尝试将目录更改为open ex1.py,当我键入cd lpthw时,它不会将目录更改为lpthw,这是
C:\Windows\System32\lpthw
但是它将lpthw附加到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>
我在网上找到了一个答案,上面说要键入python和空格,然后将ex1.py拖到Powershell中,但这又给了我这个答案
PS C:\Windows\system32\WindowsPowerShell\v1.0> python C:\Windows\System32\lpthw\ex1.py\
C:\Users\Olga\AppData\Local\Programs\Python\Python37-32\python.exe:
can't open file 'C:\Windows\System32\lpthw\ex1.py\':
[Errno 2] No such file or directory
PS C:\Windows\system32\WindowsPowerShell\v1.0>
哦。。。如何让它运行ex1.py?你知道吗
谢谢!!!!你知道吗
这很令人沮丧,但你会习惯的!你知道吗
这些目录名是一个地址,用来描述某些东西在计算机中的位置。在每个
\
右边的东西在左边的东西里面。如果你有一个路径,从左边的C:
开始,穿过许多目录,在最右边以你想使用的地方或文件结束,那就是一个完整的路径,你可以从任何地方使用它,因为它描述了一个完整的位置,没有混淆的余地。你知道吗相反,如果您只使用像“lpthw”这样的路径的一小段,它被称为相对路径,它描述了如何从当前目录开始到达某个地方。你知道吗
相对路径更短、更方便,但可能会造成混淆,因为它们的最终位置会随着您的移动而改变。完整的路径更努力,但更精确。你知道吗
非常接近:
右边的
\
表示ex1.py
是一个目录,我想这就是你的问题。去掉它,它说:我想这可能有用。你知道吗
这应该行得通,但正如Lee_Dailey评论的那样,是一个奇怪的地方;任何在
C:\Windows\System32
里面的东西最好都留给Windows来管理。在某个时候,试着找到一种方法将整个C:\Windows\System32\lpthw\
文件夹移到文档中,例如C:\Users\Olga\Documents\lpthw\
相关问题 更多 >
编程相关推荐