Python的dateutil.tz.tzstr在字符串参数上失败

时间:2014-06-18 01:16:08

标签: python timezone python-dateutil

使用dateutil 2.2,我无法让tzstr examples正常工作(见下文)。它会抛出错误'str' object has no attribute 'read'。查看代码,它在self.instream.read(1)上失败。我应该通过什么类型的?

In [3]: import dateutil.tz

In [4]: dateutil.tz.tzstr('EST5EDT')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-75889fcde3a9> in <module>()
----> 1 dateutil.tz.tzstr("PST")

/Library/Python/2.7/site-packages/dateutil/tz.pyc in __init__(self, s)
    579         self._s = s
    580
--> 581         res = parser._parsetz(s)
    582         if res is None:
    583             raise ValueError("unknown string format")

/Library/Python/2.7/site-packages/dateutil/parser.pyc in _parsetz(tzstr)
    923 DEFAULTTZPARSER = _tzparser()
    924 def _parsetz(tzstr):
--> 925     return DEFAULTTZPARSER.parse(tzstr)
    926
    927

/Library/Python/2.7/site-packages/dateutil/parser.pyc in parse(self, tzstr)
    770     def parse(self, tzstr):
    771         res = self._result()
--> 772         l = _timelex.split(tzstr)
    773         try:
    774

/Library/Python/2.7/site-packages/dateutil/parser.pyc in split(cls, s)
    148
    149     def split(cls, s):
--> 150         return list(cls(s))
    151     split = classmethod(split)
    152

/Library/Python/2.7/site-packages/dateutil/parser.pyc in next(self)
    145
    146     def next(self):
--> 147         return self.__next__()  # Python 2.x support
    148
    149     def split(cls, s):

/Library/Python/2.7/site-packages/dateutil/parser.pyc in __next__(self)
    139
    140     def __next__(self):
--> 141         token = self.get_token()
    142         if token is None:
    143             raise StopIteration

/Library/Python/2.7/site-packages/dateutil/parser.pyc in get_token(self)
     70                 nextchar = self.charstack.pop(0)
     71             else:
---> 72                 nextchar = self.instream.read(1)
     73                 while nextchar == '\x00':
     74                     nextchar = self.instream.read(1)

AttributeError: 'str' object has no attribute 'read'

0 个答案:

没有答案