我正在尝试在脚本中使用
python的bitstring模块,并且导致导入错误.从交互模式运行时不会发生此错误.
这是代码:
- import bitstring
- b = bitstring.BitArray(bin='001001111')
当像这样运行时:
- python test.py
我明白了:
- AttributeError: 'module' object has no attribute 'BitArray'
但是,当我这样做时:
- $python
- Python 2.6.5 (r265:79063,Apr 16 2010,13:57:41)
- [GCC 4.4.3] on linux2
- Type "help","copyright","credits" or "license" for more information.
- >>> import bitstring
- >>> b = bitstring.BitArray(bin='001001111')
- >>> print b
- 0b001001111
它工作得很好!它是由同一个用户运行的相同解释器.有什么指针吗?
解决方法
我预测你在当前目录中创建了一个bitstring.py.