• 命令行启动模块的Python代码研究


    pyrasite的

    __requires__ = 'pyrasite==2.0'
    import re
    import sys
    from pkg_resources import load_entry_point
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
        sys.exit(
            load_entry_point('pyrasite==2.0', 'console_scripts', 'pyrasite')()
        )
    

    mitmproxy的

    import re
    import sys
    
    from mitmproxy.tools.main import mitmproxy
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
        sys.exit(mitmproxy())
    

    Ipython的

    import re
    import sys
    
    from IPython import start_ipython
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
        sys.exit(start_ipython())
    

    pip3的

    import re
    import sys
    
    from pip._internal import main
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
        sys.exit(main())
    

    virtualenv的

    import re
    import sys
    
    from virtualenv import main
    
    if __name__ == '__main__':
        sys.argv[0] = re.sub(r'(-script.pyw?|.exe)?$', '', sys.argv[0])
        sys.exit(main())
    
    

    看完大概就能知道命令行模式启动的原理了。

  • 相关阅读:
    redis集群登陆
    锁机制
    关系型数据库事务遵循ACID原则
    前端之Css
    Python之操作redis数据库
    前端之HTML
    Excel之批量改变特定字体颜色(转载)
    jmeter之批量修改请求路径
    Python之time模块
    Python之os模块
  • 原文地址:https://www.cnblogs.com/c-x-a/p/11487290.html
Copyright © 2020-2023  润新知