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

Python 字符串拼接

  •  
  •   Kakarrot · 2018-11-29 19:08:33 +08:00 · 1493 次点击
    这是一个创建于 1967 天前的主题,其中的信息可能已经有所发展或是发生改变。
    dir = "192.168.10.245\cloud"
    
    file = "b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"
    

    怎么拼接成"\192.168.10.245\cloud\b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"

    4 条回复    2018-12-01 21:11:13 +08:00
    ech0x
        1
    ech0x  
       2018-11-29 19:20:04 +08:00
    c = "{}\{}".format(dir,file)
    ech0x
        2
    ech0x  
       2018-11-29 19:21:06 +08:00
    漏看量一个反斜杠。
    应该是
    c = "\{}\{}".format(dir,file)
    jxie0755
        3
    jxie0755  
       2018-11-30 04:59:50 +08:00
    直接用+号拼接不就行了吗........
    speedbird
        4
    speedbird  
       2018-12-01 21:11:13 +08:00
    ```python
    dir = "192.168.10.245\cloud"

    file = "b9/e1/eb/b9e1eb55-3524-4337-93c0-1b5c3c01c6f8.png"

    string = f'\{dir}\{file}'
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4945 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:41 · PVG 17:41 · LAX 02:41 · JFK 05:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.