zoukankan      html  css  js  c++  java
  • os.popen('python hello_out.py')中Python程序执行时默认的当前路径为MS-DOS CMD的默认路径

    >>> 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 .Streamshello_out.py')    # 说明Python的默认路径为'D:\pythonCode\pp4e'
    >>> pipe.read()
    'Hello shell world
    '
    

     MS-DOS的默认路径:

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

    修改默认路径:

     

    再次测试:

    D:pythonCodepp4eStreams>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
    '
    >>> pipe.close()
    
  • 相关阅读:
    MyBatis Generator 的使用
    Eclipse插件手动安装
    MyBatis中别名的设置
    MyBatis 插入时返回自增主键
    MyBatis 模糊查询
    MyBatis 多个查询条件的传递
    MyBatis 的Mapper中有小于号的处理
    spring mvc rest 方式
    jackson
    中兴阅读:你的移动阅读解决专家,助纸媒们一臂之力
  • 原文地址:https://www.cnblogs.com/ant-colonies/p/9144469.html
Copyright © 2011-2022 走看看