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

Python 和 Power shell 的字符串 Split 问题

  •  
  •   wittyfans · 2020-12-02 22:19:43 +08:00 · 1413 次点击
    这是一个创建于 1212 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天用 Poweshell 提取字符串的时候发现一个小问题:

    "cell_20201403_20201407_CONDOM_24837_30_211SZH_000000J5X.csv".split(".csv")[0]

    这条代码在 Python 中和 Power shell 中是都可以运行的,但结果为什么不一样呢?

    powershell_vs_python

    3 条回复    2020-12-02 23:33:00 +08:00
    wittyfans
        1
    wittyfans  
    OP
       2020-12-02 22:34:46 +08:00
    找到原因了,得这样写:

    ```
    "cell_20201403_20201407_CONDOM_24837_30_211SZH_000000J5X.csv" -split ".csv"
    ```

    参见: https://stackoverflow.com/a/22200431
    Lemeng
        2
    Lemeng  
       2020-12-02 22:46:11 +08:00
    自己能找到问题,印象更深刻
    wittyfans
        3
    wittyfans  
    OP
       2020-12-02 23:33:00 +08:00 via iPhone
    @Lemeng 对的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5329 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:48 · PVG 13:48 · LAX 22:48 · JFK 01:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.