V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
phx13ye
V2EX  ›  Python

请教 python 脚本里面在调一个 python 程序应该怎么做?

  •  
  •   phx13ye ·
    Alwayswithme · 2016-01-28 14:02:53 +08:00 · 2369 次点击
    这是一个创建于 3011 天前的主题,其中的信息可能已经有所发展或是发生改变。

    before: 我现在是一个 shell 脚本

    #!/bin/sh
    
    python script.py
    sslocal
    

    after: 现在想直接在script.py里做,相当于在这个脚本后面加一行 sslocal

    #!/bin/python
    
    #blablabla
    
    sslocal
    
    7 条回复    2016-01-28 14:40:13 +08:00
    wellsc
        1
    wellsc  
       2016-01-28 14:11:08 +08:00
    python parser?
    Ansen
        2
    Ansen  
       2016-01-28 14:13:11 +08:00   ❤️ 1
    简单粗爆用 subprocess.call
    crashguy
        3
    crashguy  
       2016-01-28 14:14:58 +08:00   ❤️ 1
    去搜索 python 下执行 shell 命令,能找到你想要的答案
    chinuno
        4
    chinuno  
       2016-01-28 14:21:00 +08:00   ❤️ 1
    subprocess.Popen
    参数比较多配置空间大。
    输入输出可以通过 subprocess.PIPE 来操作
    BOYPT
        5
    BOYPT  
       2016-01-28 14:28:07 +08:00   ❤️ 1
    os.system("python xxx.py") 粗暴
    RqPS6rhmP3Nyn3Tm
        6
    RqPS6rhmP3Nyn3Tm  
       2016-01-28 14:28:46 +08:00   ❤️ 1
    os.popen 粗暴
    phx13ye
        7
    phx13ye  
    OP
       2016-01-28 14:40:13 +08:00
    subprocess.run(['sslocal', '-c', configfile]) 解决,谢谢大家
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2524 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:51 · PVG 23:51 · LAX 08:51 · JFK 11:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.