我正在使用Python 2.7尝试从datetime字符串中删除尾随空格。它没有执行任务。这是我的代码:
dateString, tz = ourDate[:25], ourDate[25:]
dateString.strip()
print dateString + 'EOL' # EOL to illustrate results, below
输出如下循环结果:
Fri, 21 Dec 2018 18:50:10EOL
Greater than 24? 25
Thu, 6 Dec 2018 11:19:59 EOL
Greater than 24? 25
The, 11 Dec 2018 15:10:11EOL
Greater than 24? 25
Sun, 16 Dec 2018 22:43:07EOL
Greater than 24? 25
您会看到一个“短”日期(12月6日)在EOL子字符串之前产生一个空格。
我认为这是非常奇怪的行为。我想念什么?
您必须将剥离的值放回dateString变量