如何在列表中存储纯字符串

时间:2014-03-21 06:15:59

标签: python-2.7

第一项tests_data列表在循环中为list type,为什么?

def test__trim_value(self):
    testing_data = ["""rtsp://172.19.1.101\n""", "3600\n\r", "\n\r900\r\n"]
    expecting_data = ["rtsp://172.19.1.101", "3600", "900"]
    for should, test_item in izip(expecting_data, testing_data):
        print(repr(test_item))
        print(type(test_item))

        got = self.txt._Txt__trim_value(test_item)
        eq_(should, got)

@classmethod
def __trim_value(cls, raw_value):
    print(type(raw_value))
    print((raw_value))
    trimmed_value = raw_value.strip()
    return trimmed_value
    pass

输出

<type 'list'>
[' rtsp', '//172.19.1.101\n']
XF'rtsp://172.19.1.101\n'
<type 'str'>
<type 'str'>
rtsp://172.19.1.101

'3600\n\r'
<type 'str'>
<type 'str'>
3600

'\n\r900\r\n'
<type 'str'>
<type 'str'>

900

0 个答案:

没有答案