一、解决报错
在python运行出现错误TypeError: integer argument expected, got float。这句话的意思是:期望得到整数类型,但得到的是浮点数。
Bicubic_Img.putpixel((x, y), tuple(tmp))
'报错:TypeError: integer argument expected, got float'
'解决'
Bicubic_Img.putpixel((x, y), tuple(map(int,tmp)))
所以解决方法就是输入整数类型,但int()函数用于将字符串或数字转换为整型,而不能将序列转成整型。所以这里使用map()函数。
tmp=[1.1,2.2,3.3]
'''
int(tmp)
报错:TypeError: int() argument must be a string, a bytes-like object or a number, not 'list
'''
tmp=map(int,tmp)
'''
print(tmp)
不显示结果 <map object at 0x000001DA938C3FD0>
'''
print(list(tmp))
'结果:[1, 2, 3]'
二、map()函数的用法
①map()函数的格式是:
map(func, *iterables)
②使用map进行整数类型转换方法是:
map(int,[1,2])
③输出map()函数运行结果方法是:
print(list(map(int,[1,2.2])))
④map函数的更多使用方法:
Python的官方帮助文档 https://docs.python.org/2.7/
在命令行输入help(map)查看
help(map)
'''
help> map
Help on class map in module builtins:
class map(object)
| map(func, *iterables) --> map object
|
| Make an iterator that computes the function using arguments from
| each of the iterables. Stops when the shortest iterable is exhausted.
|
| Methods defined here:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __iter__(self, /)
| Implement iter(self).
|
| __next__(self, /)
| Implement next(self).
|
| __reduce__(...)
| Return state information for pickling.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
'''