首页 > 编程语言 > 详细

WS-DOS下Python的默认路径即为WS-DOS CMD的默认打开路径

时间:2018-06-06 14:28:28      阅读:385      评论:0      收藏:0      [点我收藏+]
>>> import os
>>> os.getcwd()
‘D:\\pythonCode\\pp4e‘
>>> os.chdir(‘Streams‘)
>>> os.getcwd()
‘D:\\pythonCode\\pp4e\\Streams‘
>>> open(‘hell_out.py‘).read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: ‘hell_out.py‘
>>> open(‘hello_out.py‘).read()
"print(‘Hello shell world‘)"
>>> pipe = os.popen(‘python3 hello_out.py‘)
>>> python3: can‘t open file ‘hello_out.py‘: [Errno 2] No such file or directory


>>> pipe = os.popen(r‘python3 .\Streams\hello_out.py‘)    # 说明Python的默认路径为‘D:\\pythonCode\\pp4e‘
>>> pipe.read()
‘Hello shell world\n‘

 MS-DOS的默认路径:

技术分享图片

 

可以对 MS-DOS的默认路径进行修改:

技术分享图片技术分享图片

技术分享图片

 

修改默认路径:

 技术分享图片

 

再次测试:

D:\pythonCode\pp4e\Streams>python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd()
‘D:\\pythonCode\\pp4e\\Streams‘
>>> open(‘hello_out.py‘).read()
"print(‘Hello shell world‘)"
>>> pipe = os.popen(‘python3 hello_out.py‘)
>>> pipe.read()
‘Hello shell world\n‘
>>> pipe.close()

 

WS-DOS下Python的默认路径即为WS-DOS CMD的默认打开路径

原文:https://www.cnblogs.com/ant-colonies/p/9144469.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!