推荐学习书目
› 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
Ewig
V2EX  ›  Python

scrapy 中的一段代码不知道其用意

  •  
  •   Ewig · Dec 22, 2018 · 2870 views
    This topic created in 2847 days ago, the information mentioned may be changed or developed.

    sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0])

    我在 scrapy 代码中发现这么一段代码

    为啥这里是把‘-script.pyw|.exe)?$' 替换 sys.argv[0]呢

    7 replies  •  2018-12-25 10:55:30 +08:00
    liuxu
        1
    liuxu  
       Dec 22, 2018
    是把 sys.argv[0]中的-script.pyw 或者.exe 删除掉吧。。
    whoami9894
        2
    whoami9894  
       Dec 22, 2018 via Android
    是替换为""
    Ewig
        4
    Ewig  
    OP
       Dec 23, 2018
    @liuxu 我知道这个意思啊,为啥这么做啊,没明白啊
    liuxu
        5
    liuxu  
       Dec 24, 2018
    @Ewig 兼容命名规则? linux 下 test,windows 下 test.exe ,以及这个代码的 test-script.pyw ,去掉多余的部分,统一程序名
    Ewig
        6
    Ewig  
    OP
       Dec 25, 2018
    @liuxu 我不知道为啥加个-scraipt
    liuxu
        7
    liuxu  
       Dec 25, 2018
    @Ewig 可能是开发时为了好区分不同逻辑层的代码吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   6060 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 03:03 · PVG 11:03 · LAX 20:03 · JFK 23:03
    ♥ Do have faith in what you're doing.