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
shawndev
V2EX  ›  Python

请问 aosabook/500lines 中 guido 写的爬虫中,__ini__ 参数中单独的 * 是什么用法?

  •  
  •   shawndev · 2017-10-15 11:56:20 +08:00 · 2229 次点击
    这是一个创建于 2384 天前的主题,其中的信息可能已经有所发展或是发生改变。
    源码地址: https://github.com/aosabook/500lines/blob/master/crawler/code/crawling.py
    第 53 行 loop=None 前面单独的星号是什么用法? google 找不到对应的答案(也可能是我没找对关键字)
    9 条回复    2017-10-15 23:41:38 +08:00
    shawndev
        1
    shawndev  
    OP
       2017-10-15 11:59:20 +08:00
    class Crawler:
    def __init__(self, roots,
    exclude=None, strict=True, # What to crawl.
    max_redirect=10, max_tries=4, # Per-url limits.
    max_tasks=10, *, loop=None):

    代码在这里
    guyskk0x0
        2
    guyskk0x0  
       2017-10-15 12:06:53 +08:00 via Android
    keyword only parameter
    shawndev
        3
    shawndev  
    OP
       2017-10-15 12:08:18 +08:00
    @guyskk0x0 那么他和 *args 和 **kwargs 有什么区别呢,怎么从中取值?
    shawndev
        4
    shawndev  
    OP
       2017-10-15 12:11:45 +08:00
    @guyskk0x0 查到了,PEP3102 万分感谢
    XIVN1987
        5
    XIVN1987  
       2017-10-15 12:12:19 +08:00 via Android
    @shawndev
    它的意思是后面的参数只能用关键字传参,不能用位置参数传参,,它本身没有值
    shawndev
        6
    shawndev  
    OP
       2017-10-15 12:59:46 +08:00
    @XIVN1987 感谢,看了下 PEP 好像有点懂了~
    mec
        7
    mec  
       2017-10-15 13:47:09 +08:00
    python3 新特性这是
    boyxupers
        8
    boyxupers  
       2017-10-15 14:28:07 +08:00 via iPhone
    3 语法有点太乱了…
    sunwei0325
        9
    sunwei0325  
       2017-10-15 23:41:38 +08:00
    @boyxupers 我怎么觉得 3 的语法很先进呢..
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2681 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:02 · PVG 00:02 · LAX 09:02 · JFK 12:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.