【发布时间】:2012-07-10 17:08:56
【问题描述】:
Python 3.3 的测试版已经发布,非常棒。
新改版的time 模块具有get_clock_info 方法来获取有关平台的许多逻辑时钟的信息。 PEP 418 描述了新的时间模块。
当我尝试运行 PEP 418 clock_resolution.py 中引用的示例程序之一时,我在下面的第 54 行得到 TypeError: 'namespace' object is not iterable:
46 clocks = ['clock', 'perf_counter', 'process_time']
47 if hasattr(time, 'monotonic'):
48 clocks.append('monotonic')
49 clocks.append('time')
50 for name in clocks:
51 func = getattr(time, name)
52 test_clock("%s()" % name, func)
53 info = time.get_clock_info(name)
54 if 'precision' in info:
55 print("- announced precision: %s" % format_duration(info['precision']))
56 print("- implementation: %s" % info['implementation'])
57 print("- resolution: %s" % format_duration(info['resolution']))
第 53 行的“信息”包含:
>>> info
namespace(adjustable=True, implementation='gettimeofday()', monotonic=False, resolution=1e-06)
那么如何迭代一个命名空间对象呢?
【问题讨论】:
-
您应该在 Python 错误跟踪器上打开一个关于此的问题:bugs.python.org
-
@NedDeily:哪个有错误? Python 3.3 还是 PEP 418 中的示例代码?在我看来,您应该能够迭代命名空间对象,但我没有看到这个记录..
-
我认为要记录的问题是 PEP 中的示例程序由于功能实现的变化而不再工作。
标签: python namespaces python-3.x python-3.3