简体   繁体   English

在当前目录中打开python shell

[英]Open python shell in the current directory

I want to open python shell in the current directory like cmd. 我想在当前目录(如cmd)中打开python shell。 My system is windows 10. How can I achieve that? 我的系统是Windows10。如何实现? Something like that: Suppose that I open a directory in D disk, let's say the path is "D:\\PythonProjects". 这样的事情:假设我在D盘中打开一个目录,假设路径为“ D:\\ PythonProjects”。 I tried to open cmd in current directory, in cmd I type "python" to get python shell, but the work directory of python didn't chage. 我试图在当前目录中打开cmd,在cmd中我键入“ python”以获取python shell,但是python的工作目录没有变化。

You can just simply open shell and than 您只需打开外壳,然后

import os
os.chdir(" ")

In between quotes you can specify path were you want to open that 您可以在引号之间指定要打开的路径

You can also see current path by 您还可以通过以下方式查看当前路径

os.getcwd()

Did you try something like this in command line? 您是否在命令行中尝试过类似的方法?

C:> D:
D:> cd PythonProjects
D:\PythonProjects> python
[Something about Python interpreter]
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM