V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Dec 2, 2020 · 1842 views
    This topic created in 1983 days ago, the information mentioned may be changed or developed.

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

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

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

    powershell_vs_python

    3 replies    2020-12-02 23:33:00 +08:00
    wittyfans
        1
    wittyfans  
    OP
       Dec 2, 2020
    找到原因了,得这样写:

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

    参见: https://stackoverflow.com/a/22200431
    Lemeng
        2
    Lemeng  
       Dec 2, 2020
    自己能找到问题,印象更深刻
    wittyfans
        3
    wittyfans  
    OP
       Dec 2, 2020 via iPhone
    @Lemeng 对的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5394 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 08:05 · PVG 16:05 · LAX 01:05 · JFK 04:05
    ♥ Do have faith in what you're doing.