Python的日期util.tz.tzstr字符串argumen失败

2024-10-02 12:33:43 发布

您现在位置:Python中文网/ 问答频道 /正文

使用dateutil2.2,我无法使^{} 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'

Tags: inselfparserreadpackagesdeflibrarysite

热门问题