相关疑难解决方法(0)

Python string.strip剥离了太多字符

我使用Python 3来处理文件名,这是我的代码:

name = 'movies.csv'
table_name = name.strip(".csv")
Run Code Online (Sandbox Code Playgroud)

table_name的期望值应该是"movies",而table_name仍然返回"movie".

它为什么这样做?

python

13
推荐指数
2
解决办法
2446
查看次数

使用 python 2.7 和 3.5 的 string.strip() 中的奇怪错误

在使用 string.strip() 进行非常简单的字符串操作时,我得到了一些非常奇怪的结果。我想知道这是一个只影响我的问题(我的 python 安装有问题?)还是一个常见的错误?

这个错误是非常有线的,它是这样的:

>>> a = './omqbEXPT.pool'
>>> a.strip('./').strip('.pool')
'mqbEXPT' #the first 'o' is missing!!!
Run Code Online (Sandbox Code Playgroud)

仅当 'o' 跟在 './' 之后时才会发生!

>>> a = './xmqbEXPT.pool'
>>> a.strip('./').strip('.pool')
'xmqbEXPT'
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?!我已经在 python 2.7 和 3.5 上对此进行了测试,结果没有改变。

python string strip

1
推荐指数
1
解决办法
2112
查看次数

标签 统计

python ×2

string ×1

strip ×1