编辑:
在执行以下代码之前,我犯了一个非常微不足道的错误,将bytes
绑定到先前的其他内容上。这个问题现在完全是微不足道的,可能对任何人都没有帮助。抱歉。
原始问题:
代码:
import sys
print(sys.version)
b = bytes([10, 20, 30, 40])
print(b)
输出:
3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-38-21fec5626bc3> in <module>()
1 import sys
2 print(sys.version)
----> 3 b = bytes([10, 20, 30, 40])
4 print(b)
TypeError: 'bytes' object is not callable
文档:
Type: bytes
String form: b'hello world'
Length: 11
Docstring:
bytes(iterable_of_ints) -> bytes
bytes(string, encoding[, errors]) -> bytes
bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer
bytes(int) -> bytes object of size given by the parameter initialized with null bytes
bytes() -> empty bytes object
Construct an immutable array of bytes from:
- an iterable yielding integers in range(256)
- a text string encoded using the specified encoding
- any object implementing the buffer API.
- an integer
我做错了什么?