py: Make 'bytes' be a proper type, support standard constructor args.
This commit is contained in:
@@ -4,8 +4,36 @@ print(str(a))
|
||||
print(repr(a))
|
||||
print(a[0], a[2])
|
||||
print(a[-1])
|
||||
print(str(a, "utf-8"))
|
||||
print(str(a, "utf-8", "ignore"))
|
||||
try:
|
||||
str(a, "utf-8", "ignore", "toomuch")
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
s = 0
|
||||
for i in a:
|
||||
s += i
|
||||
print(s)
|
||||
|
||||
|
||||
print(bytes("abc", "utf-8"))
|
||||
print(bytes("abc", "utf-8", "replace"))
|
||||
try:
|
||||
bytes("abc")
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
try:
|
||||
bytes("abc", "utf-8", "replace", "toomuch")
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
print(bytes(3))
|
||||
|
||||
print(bytes([3, 2, 1]))
|
||||
print(bytes(range(5)))
|
||||
|
||||
def gen():
|
||||
for i in range(4):
|
||||
yield i
|
||||
print(bytes(gen()))
|
||||
|
Reference in New Issue
Block a user