nunicodeessscape codec can't decode bytes in position2-3:truncated\UXXXXXXXX escape
描述:im=Image.open("C:\Users\Administrator\Desktop\mylove.jpg")
解决方法:
im=Image.open(r"C:\Users\Administrator\Desktop\mylove.jpg")
TypeError: 'int' object is not iterable
描述:y=[i for i in 7]>>
解决方法:
y=[i for i in range(7)]
TypeError: can only concatenate tuple (not "float") to tuple
描述:
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
xs = [i + 0.1 for i in enumerate(movies)]
print(xs)
>>
解决方法:
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
xs = [i + 0.1 for i, _ in enumerate(movies)]
print(xs)
补充:enumerate()函数返回的enumerate对象,是由多个元组组成,每次迭代取出的是一个元组,所以应该用两个参数接受迭代出来的值,测试
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]print(enumerate(movies))print(list(enumerate(movies)))for i inenumerate(movies):print(i)for i inenumerate(movies):for j ini:print(j)for i,j inenumerate(movies):print(i)print(j)
个人理解,如果我们只取单个元组中的一个值,那么第二个值通常用“_”表示,如:
for i,_ inenumerate(movies):print(i)
问题:计算结果输出错误值
描述
from numba importjitimporttime
@jitdeffoo(x,y):
tt=time.time()
s=0for i inrange(x,y):
s+=iprint('Time used: {} sec'.format(time.time()-tt))returnsprint(foo(1,100000000))
>>887459712
^_^来自鱼c论坛鱼友
原因分析:int整型溢出
用c代码测试如下
intmain()
{//std::cout << sizeof(int);//std::cout << sizeof(int) * 8;
int a = 4999999950000000;
std::cout<
int b = 2147483647;
std::cout<< "b初始化值为2147483647,即4字节int类型,能表示的最大值" << b << "\n";//2147483647
std::cout << b+1 << "\n";//-2147483648
std::cout << b + 2 << "\n";//最大值-2147483647
std::cout << b + 3 << "\n";//-2147483646
std::cout<< b + 3 + 2147483647<< "\n";
std::cout<< b + 3 + 2147483647*2 << "\n";//-2147483646
}
总结:
·int占4个字节,用32位表示,第一位表示正负号,1表示负数,0表示正,所以最大正数为01111111111111111111111111111111(首位为0,后31位为1)所以能表示的最大值就是2147483647
·一旦超出这个值,它把第一位表示符号的设置为1(或者它自动进一位),此时,它代表一个负数,那么为什么是-2147483648呢,用工具转换一下,-2147483648值为-10000000000000000000000000000000,那它就是把第一位为1的时候,其他所有位为0了
·每次到了存储位不够用的时候,它又循环以上的操作(正转负,负转正,第一位的0-1不断切换)
·所以最后,大概可以推算出为什么4999999950000000输出的是887459712
TypeError: Cannot handle this data type
~这个问题有待研究,应该是matplitlib库中画图的“轴”plt或axes无法理解传入的数据~
_tkinter.TclError: image "pyimage1" doesn't exist
可能是你建了两个root窗口,可以将
wlcm_scrn = tkinter.Tk()
改为
wlcm_scrn = tkinter.Toplevel()