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

Python 语法,这是哪条规则允许这样做的?

  •  
  •   chaleaoch · 2020-05-14 21:09:41 +08:00 · 4202 次点击
    这是一个创建于 1414 天前的主题,其中的信息可能已经有所发展或是发生改变。

    图片

    我试了一下,是有效的.

    第 1 条附言  ·  2020-05-15 00:01:22 +08:00
    a_dct = {
        'key': 'value to looooooooooooooooooooong'
                'looooooooooooooooooooooooooooooong',
        'another_key':'no error happened'
    }
    
    

    大概是这个意思. 另外 有道做图床 是我在B站看到一个up主这么做的. 哎 没想到娃...原来不行.

    第 2 条附言  ·  2020-05-15 00:05:39 +08:00
    没见过世面的样子.

    另外这个帖子对于楼主来说最大的收获是, https://sm.ms/ 呵呵呵,,,,
    22 条回复    2020-05-15 10:09:39 +08:00
    ClericPy
        1
    ClericPy  
       2020-05-14 21:12:07 +08:00   ❤️ 1
    {
    "canTryAgain": false,
    "scope": "SECURITY",
    "error": "207",
    "message": "Message[AUTHENTICATION_FAILURE]: User token must be authenticated.",
    "objectUser": null
    }
    lithbitren
        2
    lithbitren  
       2020-05-14 21:12:44 +08:00   ❤️ 2
    看不到图,为啥我在 v2 经常看不到图。。
    wellsc
        3
    wellsc  
       2020-05-14 21:14:05 +08:00   ❤️ 1
    虽然不知道你在说什么,但是觉得好厉害的样子
    wjm2038
        4
    wjm2038  
       2020-05-14 21:14:23 +08:00 via Android   ❤️ 1
    图没了
    cherbim
        5
    cherbim  
       2020-05-14 21:19:52 +08:00   ❤️ 1
    换个图床
    Cusmate
        6
    Cusmate  
       2020-05-14 21:22:14 +08:00   ❤️ 1
    图片不显示了,AUTHENTICATION_FAILURE
    Trim21
        8
    Trim21  
       2020-05-14 21:41:08 +08:00
    不行
    Cuo
        9
    Cuo  
       2020-05-14 21:45:28 +08:00
    楼主感到疑惑的地方是字符串可以分成两行来写吗?
    hakono
        10
    hakono  
       2020-05-14 21:46:38 +08:00   ❤️ 1
    实在看不下去了,LZ 找个图床吧,别想着用有道的图片链接了,有道不做登陆检测不得被你们撸成图床

    https://sm.ms/
    Cuo
        11
    Cuo  
       2020-05-14 21:49:03 +08:00   ❤️ 1
    为了看不到图的 V 友

    ```python
    HOGE = {
    'FOO': r'^([0-9]|[1-9]\d|'
    r'[1-5]\d{4}|6[0-4]',
    'HEGO': 'string'
    }
    ```
    图上的内容大致是这么个意思
    ila
        12
    ila  
       2020-05-14 21:49:52 +08:00 via Android
    盲猜 value 变成了 tuple
    lithbitren
        13
    lithbitren  
       2020-05-14 22:08:44 +08:00   ❤️ 1
    盲猜字符串不用加号也能拼接,而且换行空格缩进不影响拼接
    ClericPy
        14
    ClericPy  
       2020-05-14 22:11:02 +08:00   ❤️ 1
    字符串本来就可以不用加号拼接

    string - Wrap long lines in Python - Stack Overflow - https://stackoverflow.com/questions/3346230/wrap-long-lines-in-python

    google 搜 python string too long 就行了
    imn1
        15
    imn1  
       2020-05-15 01:32:36 +08:00
    我经常这样写
    还可以字节类型
    b'……'
    '……'
    '……'
    '……',

    场合:一个 base64 编码的文件……
    imn1
        16
    imn1  
       2020-05-15 01:36:15 +08:00
    呃,上面写错了,每行前面都要 b 开头,不然会报错
    laike9m
        17
    laike9m  
       2020-05-15 02:32:16 +08:00   ❤️ 2
    一般建议这么写

    a_dct = {
    'key': ('value to looooooooooooooooooooong'
    'looooooooooooooooooooooooooooooong'),
    'another_key':'no error happened'
    }

    加上括号
    zhidian
        18
    zhidian  
       2020-05-15 02:48:24 +08:00
    C 语言来的。
    zhidian
        19
    zhidian  
       2020-05-15 02:50:19 +08:00   ❤️ 1
    ysc3839
        20
    ysc3839  
       2020-05-15 08:52:15 +08:00 via Android
    大概是继承自 C 语言的规则。
    no1xsyzy
        21
    no1xsyzy  
       2020-05-15 09:46:36 +08:00   ❤️ 1
    这个甚至可以混杂 f-string r-string 甚至 three quote string
    print("normal string\n"
    r"r-string, but \n is just \n" ", for LF use another normal string at end\n"
    f"f-string, {2+3=}\n"
    f"""three-quote f-string{ " ".join(str(i) for i in range(10)) }""")
    bwangel
        22
    bwangel  
       2020-05-15 10:09:39 +08:00   ❤️ 1
    https://docs.python-guide.org/writing/style/#line-continuations

    Python Guide 这个文档真的挺好的,值得一读。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5557 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 01:38 · PVG 09:38 · LAX 18:38 · JFK 21:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.