我试图从存储在矩阵中的时间戳(或列表,如果你想要)删除字符。我想提取该项目,并在剥离不需要的字符后使用它作为文件名(它应该在原始列表中保持不变)。我对通常使用它的剥离和其他字符串操作非常熟悉,但是现在我用这个来填充,我不知道发生了什么,我尝试了几乎所有的东西。我想获得'2011092723492'而不是原来的'2011.09.27 23:49 2'。在这个例子中只是':'被替换,以使它更容易。我错过了什么吗?:python从列表项中删除字符
for x in FILEmatrix:
flnm = str(x[4]) # or just 'x[4]' doesn't matter it is a string for sure
print type(flnm) # <type 'str'> OK, not a list or whatever
print 'check1: ', flnm # '2011.09.27 23:49 2'
flnm.strip(':') # i want to get '2011092723492', ':' for starters, but...
print 'check2: ', flnm # nothing... '2011.09.27 23:49 2'
string.strip(flnm,':')
print 'check3: ', flnm # nothing... '2011.09.27 23:49 2'
flnm = flnm.strip(':')
print 'check4: ', flnm # nothing... '2011.09.27 23:49 2'
flnm.replace(':', '')
print 'check5: ', flnm # nothing... '2011.09.27 23:49 2'
非常感谢!
另请参阅:http:// stackoverflow。com/questions/7588511/format-a-datetime-into-a-string-with-milliseconds –