2006年01月09日 星期一 11:23
大小写问题?Image->image? 按理说windows不区分大小写啊,怪.你的lib目录也有些怪,一会c:,一会d:的 >------------------------------ > >Message: 5 >Date: Mon, 9 Jan 2006 05:53:41 +0800 >From: " ?? " <ibrick at 163.com> >Subject: [python-chinese] ?idle?????DOS??????????? >To: "python-chinese" <python-chinese at lists.python.cn> >Message-ID: <43C18D66.09B6DB.25282> >Content-Type: text/plain; charset="gb2312" > >python-chinese,您好! > > 哪位牛人来指点指点,程序目的是为了输出一组编码的图像, >在IDLE中运行完成,用python.exe g.py就不行了,太怪了=:< > >================================================================= >错误信息: >raceback (most recent call last): > File "g.py", line 5, in ? > import Image > File "C:\Python24\Lib\site-packages\PIL\Image.py", line 68, in ? > import os, string, sys > File "D:\Python24\Lib\string.py", line 83, in ? > import re as _re > File "D:\Python24\lib\re.py", line 20, in ? > >AttributeError: 'module' object has no attribute 'search' > >******************************************************************* > > >程序内容: >#-------------------------------------------------------------- ># -*- coding: cp936 -*- > >from Tkinter import * >from tkFileDialog import * >import Image >import ImageFont >import ImageDraw > >outpath = askdirectory () >font = 'D:/WINDOWS/Fonts/ARIAL.TTF' # 字体文件路径 >list = [(32,2), (14,4), (26,8)] >strls = [] >all = 0 >accls = {} > >for i in list: > all += 9*i[0]*i[1] > for l in range(1, i[0] + 1): > for g in range(1,10): > n = g*100+l > for b in range(i[1]): > strls.append(str(n)) > >if all != len(strls): > print "len = %d, all = %d" % (len(strls),all) > print "Error" > sys.exit(1) > >for c in strls: > if accls.has_key(c): > accls[c] += 1 > else: > accls[c] = 1 > >allstr = accls.keys() >allstr.sort() > >endls = [] >for ch in allstr: > endls.append((ch,accls[ch])) > > >for text in endls: > im = Image.new("RGB",(260,88),(66,17,17)) > draw = ImageDraw.Draw(im) > draw.setfont(ImageFont.truetype(font,95)) ># Arial = ImageFont.truetype(font,95) > > for i in [0,1,2]: > draw.text((48+i*55,-11),text[0][i],(255,211,0)) > fname = outpath + '/' + u'哑膜PP背胶-0.06×0.02-%d张-%s.tif' % (text[1],text[0]) > im.save(fname) ># --------------------------- end ------------------------------------ > >错误信息: >raceback (most recent call last): > File "g.py", line 5, in ? > import Image > File "C:\Python24\Lib\site-packages\PIL\Image.py", line 68, in ? > import os, string, sys > File "D:\Python24\Lib\string.py", line 83, in ? > import re as _re > File "D:\Python24\lib\re.py", line 20, in ? > >AttributeError: 'module' object has no attribute 'search' > > > > 致 >礼! > > > 冷眼 > ibrick at 163.com > 2006-01-09 > >------------------------------ > >Message: 6 >Date: Mon, 9 Jan 2006 08:14:08 +0800 >From: Qu Jianning <redfox.qu at gmail.com> >Subject: [python-chinese] Re: python-chinese Digest, Vol 25, Issue 38 >To: python-chinese at lists.python.cn >Message-ID: <62b1fc650601081614j5a1c6a3ak at mail.gmail.com> >Content-Type: text/plain; charset="gb2312" > >我觉得还是魏忠的好一点,起码代码清楚,重要的是符合题意 > >在06-1-8,python-chinese-request at lists.python.cn < >python-chinese-request at lists.python.cn> 写道: >> >> Send python-chinese mailing list submissions to >> python-chinese at lists.python.cn >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://python.cn/mailman/listinfo/python-chinese >> or, via email, send a message with subject or body 'help' to >> python-chinese-request at lists.python.cn >> >> You can reach the person managing the list at >> python-chinese-owner at lists.python.cn >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of python-chinese digest..." >> >> >> Today's Topics: >> >> 1. Re: ?????????? (yzhh) >> 2. Re: ?????????? (???) >> 3. Re: Re: ?????????? (??) >> 4. Re: Re: ?????????? (??) >> 5. Re: Re: ?????????? (???) >> >> >> ---------------------------------------------------------------------- >> >> Message: 1 >> Date: Sun, 08 Jan 2006 18:04:27 +0800 >> From: yzhh <yezonghui at gmail.com> >> Subject: [python-chinese] Re: ?????????? >> To: python-chinese at lists.python.cn >> Message-ID:1 at sea.gmane.org> >> Content-Type: text/plain; charset=gb2312 >> >> 魏忠 wrote: >> >> > 据说这道题来自google的面试: >> > 已知: >> > f(1)=1 >> > f(10)=2 >> > f(11)=4 >> > f(n)表示从1到n的全部整数中1这个数字出现的次数 >> > 写一个尽可能短的程序,计算出下一次f(n)=n时,n等于多少 >> > 分析清楚之后,用python实现很容易。忙累了的高手也可以休息一下试试哦! >> > >> > 这里给出答案:199981 >> > D:\py>python -m profile f11.py >> > 答案是:199981 >> > 199985 function calls in 1.582 CPU seconds >> > >> > 开飞机的舒克 >> > http://www.lvye.org/shuke >> > msn:weizhong at netease.com >> >> 这是我的代码,比较快,请指教 >> >> def fac(n): >> """Comput factorial of n""" >> r = 1 >> i = 1 >> while (i<=n): >> r *= i >> i += 1 >> return r >> >> def C(n,m): >> """Comput combinatory: select m from n""" >> return fac(n)/(fac(m)*fac(n-m)) >> >> def f(n): >> if n == 0: >> return 0 >> >> d = 0 >> m = 1 >> while m <= n : >> m *= 10 >> d += 1 >> m /= 10 >> d -= 1 #now m == 10**d <= n < 10**(d+1) >> >> count = 0 >> for i in range(1,d+1): >> #count += No. of '1's where there is i occurrence of '1' in a >> number >> count += i * C(d,i) * (9 **(d-i)) >> r = (n / m) * count >> if (n / m ) == 1: >> r += n - m + 1 >> else: >> r += m >> r += f(n%m) >> return r >> >> #import pdb >> #pdb.set_trace() >> >> n2 = 2 >> while n2 > f(n2): >> n2 += n2 - f(n2) >> # print "f(" + str(n2) + ") = " + str(f(n2)) >> n1 = n2 / 2 >> n = n2 >> while (n != f(n)): >> n = (n1 + n2) / 2 >> if n > f(n): >> n1 = n >> else: >> n2 = n >> # print "f(" + str(n) + ") = " + str(f(n)) >> >> print n >> -- >> regards, >> yzhh >> >> >> >> ------------------------------ >> >> Message: 2 >> Date: Sun, 8 Jan 2006 11:05:02 +0000 >> From: ??? <leexiaofeng at gmail.com> >> Subject: Re: [python-chinese] ?????????? >> To: python-chinese at lists.python.cn >> Message-ID: <87af76540601080305o28798527i at mail.gmail.com> >> Content-Type: text/plain; charset=GB2312 >> >> 在 06-1-7,魏忠<weizhong2004 at gmail.com> 写道: >> > 据说这道题来自google的面试: >> > 已知: >> > f(1)=1 >> > f(10)=2 >> > f(11)=4 >> > f(n)表示从1到n的全部整数中1这个数字出现的次数 >> > 写一个尽可能短的程序,计算出下一次f(n)=n时,n等于多少 >> > 分析清楚之后,用python实现很容易。忙累了的高手也可以休息一下试试哦! >> > >> > 这里给出答案:199981 >> > D:\py>python -m profile f11.py >> > 答案是:199981 >> > 199985 function calls in 1.582 CPU seconds >> > >> 一个非常蹩脚的实现,验证了你的答案,请指教 >> #!/usr/bin/env python >> def howmany1( n ): >> count = 0 >> while(n != 0 ): >> r = n % 10 >> n = n / 10 >> if( r != 1 ): >> continue >> count += 1 >> >> return count >> >> def f11(n): >> count = 0 >> while(n>0): >> count += howmany1(n) >> n -= 1 >> return count >> >> print f11(199981) >> >> ------------------------------ >> >> Message: 3 >> Date: Sun, 8 Jan 2006 19:07:43 +0800 >> From: ?? <weizhong2004 at gmail.com> >> Subject: Re: [python-chinese] Re: ?????????? >> To: python-chinese at lists.python.cn >> Message-ID: <acd2ebf20601080307h29b513c5p at mail.gmail.com> >> Content-Type: text/plain; charset="gb2312" >> >> 老兄的代码果真飞快! >> 俺的慢代码是这样的: >> >> result=[1] >> temp=1 >> x=2 >> while True: >> jg=str(x).count('1')+temp >> if jg==x:print x;break; >> x+=1 >> temp=jg >> >> >> 在06-1-8,yzhh <yezonghui at gmail.com> 写道: >> > >> > 魏忠 wrote: >> > >> > > 据说这道题来自google的面试: >> > > 已知: >> > > f(1)=1 >> > > f(10)=2 >> > > f(11)=4 >> > > f(n)表示从1到n的全部整数中1这个数字出现的次数 >> > > 写一个尽可能短的程序,计算出下一次f(n)=n时,n等于多少 >> > > 分析清楚之后,用python实现很容易。忙累了的高手也可以休息一下试试哦! >> > > >> > > 这里给出答案:199981 >> > > D:\py>python -m profile f11.py >> > > 答案是:199981 >> > > 199985 function calls in 1.582 CPU seconds >> > > >> > > 开飞机的舒克 >> > > http://www.lvye.org/shuke >> > > msn:weizhong at netease.com >> > >> > 这是我的代码,比较快,请指教 >> > >> > def fac(n): >> > """Comput factorial of n""" >> > r = 1 >> > i = 1 >> > while (i<=n): >> > r *= i >> > i += 1 >> > return r >> > >> > def C(n,m): >> > """Comput combinatory: select m from n""" >> > return fac(n)/(fac(m)*fac(n-m)) >> > >> > def f(n): >> > if n == 0: >> > return 0 >> > >> > d = 0 >> > m = 1 >> > while m <= n : >> > m *= 10 >> > d += 1 >> > m /= 10 >> > d -= 1 #now m == 10**d <= n < 10**(d+1) >> > >> > count = 0 >> > for i in range(1,d+1): >> > #count += No. of '1's where there is i occurrence of '1' in a >> > number >> > count += i * C(d,i) * (9 **(d-i)) >> > r = (n / m) * count >> > if (n / m ) == 1: >> > r += n - m + 1 >> > else: >> > r += m >> > r += f(n%m) >> > return r >> > >> > #import pdb >> > #pdb.set_trace() >> > >> > n2 = 2 >> > while n2 > f(n2): >> > n2 += n2 - f(n2) >> > # print "f(" + str(n2) + ") = " + str(f(n2)) >> > n1 = n2 / 2 >> > n = n2 >> > while (n != f(n)): >> > n = (n1 + n2) / 2 >> > if n > f(n): >> > n1 = n >> > else: >> > n2 = n >> > # print "f(" + str(n) + ") = " + str(f(n)) >> > >> > print n >> > -- >> > regards, >> > yzhh >> > >> > _______________________________________________ >> > python-chinese >> > Post: send python-chinese at lists.python.cn >> > Subscribe: send subscribe to python-chinese-request at lists.python.cn >> > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn >> > Detail Info: http://python.cn/mailman/listinfo/python-chinese >> > >> >> >> >> -- >> >> 开飞机的舒克 >> http://www.lvye.org/shuke >> msn:weizhong at netease.com >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> http://lists.exoweb.net/pipermail/python-chinese/attachments/20060108/038989f6/attachment-0001.htm >> >> ------------------------------ >> >> Message: 4 >> Date: Sun, 8 Jan 2006 19:28:42 +0800 >> From: ?? <weizhong2004 at gmail.com> >> Subject: Re: [python-chinese] Re: ?????????? >> To: python-chinese at lists.python.cn >> Message-ID: <acd2ebf20601080328i70c8f6bfp at mail.gmail.com> >> Content-Type: text/plain; charset="gb2312" >> >> 老兄的代码速度很快,但俺没有看懂.能再加点注释么? >> 在俺的机器上,你的代码 >> D:\py>python -m profile f112.py >> 199981 >> 8557 function calls (7799 primitive calls) in 0.118 CPU seconds >> 当俺将你代码中的 range函数改为 xrange 之后,性能又提高了将近一倍 >> >> >> 在06-1-8,yzhh <yezonghui at gmail.com> 写道: >> > >> > 魏忠 wrote: >> > >> > > 据说这道题来自google的面试: >> > > 已知: >> > > f(1)=1 >> > > f(10)=2 >> > > f(11)=4 >> > > f(n)表示从1到n的全部整数中1这个数字出现的次数 >> > > 写一个尽可能短的程序,计算出下一次f(n)=n时,n等于多少 >> > > 分析清楚之后,用python实现很容易。忙累了的高手也可以休息一下试试哦! >> > > >> > > 这里给出答案:199981 >> > > D:\py>python -m profile f11.py >> > > 答案是:199981 >> > > 199985 function calls in 1.582 CPU seconds >> > > >> > > 开飞机的舒克 >> > > http://www.lvye.org/shuke >> > > msn:weizhong at netease.com >> > >> > 这是我的代码,比较快,请指教 >> > >> > def fac(n): >> > """Comput factorial of n""" >> > r = 1 >> > i = 1 >> > while (i<=n): >> > r *= i >> > i += 1 >> > return r >> > >> > def C(n,m): >> > """Comput combinatory: select m from n""" >> > return fac(n)/(fac(m)*fac(n-m)) >> > >> > def f(n): >> > if n == 0: >> > return 0 >> > >> > d = 0 >> > m = 1 >> > while m <= n : >> > m *= 10 >> > d += 1 >> > m /= 10 >> > d -= 1 #now m == 10**d <= n < 10**(d+1) >> > >> > count = 0 >> > for i in range(1,d+1): >> > #count += No. of '1's where there is i occurrence of '1' in a >> > number >> > count += i * C(d,i) * (9 **(d-i)) >> > r = (n / m) * count >> > if (n / m ) == 1: >> > r += n - m + 1 >> > else: >> > r += m >> > r += f(n%m) >> > return r >> > >> > #import pdb >> > #pdb.set_trace() >> > >> > n2 = 2 >> > while n2 > f(n2): >> > n2 += n2 - f(n2) >> > # print "f(" + str(n2) + ") = " + str(f(n2)) >> > n1 = n2 / 2 >> > n = n2 >> > while (n != f(n)): >> > n = (n1 + n2) / 2 >> > if n > f(n): >> > n1 = n >> > else: >> > n2 = n >> > # print "f(" + str(n) + ") = " + str(f(n)) >> > >> > print n >> > -- >> > regards, >> > yzhh >> > >> > _______________________________________________ >> > python-chinese >> > Post: send python-chinese at lists.python.cn >> > Subscribe: send subscribe to python-chinese-request at lists.python.cn >> > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn >> > Detail Info: http://python.cn/mailman/listinfo/python-chinese >> > >> >> >> >> -- >> >> 开飞机的舒克 >> http://www.lvye.org/shuke >> msn:weizhong at netease.com >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> http://lists.exoweb.net/pipermail/python-chinese/attachments/20060108/507404fc/attachment-0001.html >> >> ------------------------------ >> >> Message: 5 >> Date: Sun, 8 Jan 2006 11:36:29 +0000 >> From: ??? <leexiaofeng at gmail.com> >> Subject: Re: [python-chinese] Re: ?????????? >> To: python-chinese at lists.python.cn >> Message-ID: <87af76540601080336t535eef15w at mail.gmail.com> >> Content-Type: text/plain; charset=GB2312 >> >> 我想他的代码是不是直接算出比这个数小的数中所有1的个数,而不是一个一个加起来。 >> >> 在 06-1-8,魏忠<weizhong2004 at gmail.com> 写道: >> > 老兄的代码速度很快,但俺没有看懂.能再加点注释么? >> > 在俺的机器上,你的代码 >> > D:\py>python -m profile f112.py >> > 199981 >> > 8557 function calls (7799 primitive calls) in 0.118 CPU seconds >> > 当俺将你代码中的 range函数改为 xrange 之后,性能又提高了将近一倍 >> > >> > >> > 在06-1-8,yzhh <yezonghui at gmail.com> 写道: >> > > 魏忠 wrote: >> > > >> > > > 据说这道题来自google的面试: >> > > > 已知: >> > > > f(1)=1 >> > > > f(10)=2 >> > > > f(11)=4 >> > > > f(n)表示从1到n的全部整数中1这个数字出现的次数 >> > > > 写一个尽可能短的程序,计算出下一次f(n)=n时,n等于多少 >> > > > 分析清楚之后,用python实现很容易。忙累了的高手也可以休息一下试试哦! >> > > > >> > > > 这里给出答案:199981 >> > > > D:\py>python -m profile f11.py >> > > > 答案是:199981 >> > > > 199985 function calls in 1.582 CPU seconds >> > > > >> > > > 开飞机的舒克 >> > > > http://www.lvye.org/shuke >> > > > msn:weizhong at netease.com >> > > >> > > 这是我的代码,比较快,请指教 >> > > >> > > def fac(n): >> > > """Comput factorial of n""" >> > > r = 1 >> > > i = 1 >> > > while (i<=n): >> > > r *= i >> > > i += 1 >> > > return r >> > > >> > > def C(n,m): >> > > """Comput combinatory: select m from n""" >> > > return fac(n)/(fac(m)*fac(n-m)) >> > > >> > > def f(n): >> > > if n == 0: >> > > return 0 >> > > >> > > d = 0 >> > > m = 1 >> > > while m <= n : >> > > m *= 10 >> > > d += 1 >> > > m /= 10 >> > > d -= 1 #now m == 10**d <= n < 10**(d+1) >> > > >> > > count = 0 >> > > for i in range(1,d+1): >> > > #count += No. of '1's where there is i occurrence of '1' in a >> > number >> > > count += i * C(d,i) * (9 **(d-i)) >> > > r = (n / m) * count >> > > if (n / m ) == 1: >> > > r += n - m + 1 >> > > else: >> > > r += m >> > > r += f(n%m) >> > > return r >> > > >> > > #import pdb >> > > #pdb.set_trace() >> > > >> > > n2 = 2 >> > > while n2 > f(n2): >> > > n2 += n2 - f(n2) >> > > # print "f(" + str(n2) + ") = " + str(f(n2)) >> > > n1 = n2 / 2 >> > > n = n2 >> > > while (n != f(n)): >> > > n = (n1 + n2) / 2 >> > > if n > f(n): >> > > n1 = n >> > > else: >> > > n2 = n >> > > # print "f(" + str(n) + ") = " + str(f(n)) >> > > >> > > print n >> > > -- >> > > regards, >> > > yzhh >> > > >> > > _______________________________________________ >> > > python-chinese >> > > Post: send python-chinese at lists.python.cn >> > > Subscribe: send subscribe to >> > python-chinese-request at lists.python.cn >> > > Unsubscribe: send unsubscribe to >> > python-chinese-request at lists.python.cn >> > > Detail Info: >> > http://python.cn/mailman/listinfo/python-chinese >> > > >> > >> > >> > >> > -- >> > >> > >> > 开飞机的舒克 >> > http://www.lvye.org/shuke >> > msn:weizhong at netease.com >> > _______________________________________________ >> > python-chinese >> > Post: send python-chinese at lists.python.cn >> > Subscribe: send subscribe to >> > python-chinese-request at lists.python.cn >> > Unsubscribe: send unsubscribe to >> > python-chinese-request at lists.python.cn >> > Detail Info: >> > http://python.cn/mailman/listinfo/python-chinese >> > >> > >> >> ------------------------------ >> >> _______________________________________________ >> python-chinese mailing list >> python-chinese at lists.python.cn >> http://python.cn/mailman/listinfo/python-chinese >> >> End of python-chinese Digest, Vol 25, Issue 38 >> ********************************************** >> >-------------- next part -------------- >An HTML attachment was scrubbed... >URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060109/25abdc64/attachment.html > >------------------------------ > >_______________________________________________ >python-chinese mailing list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > >End of python-chinese Digest, Vol 25, Issue 39 >********************************************** > = = = = = = = = = = = = = = = = = = = = Best Wishes.^^ Beisi Xu 2006-01-09 Email:xubeisi at ustc.edu QQ :2+3=0+5 14=2×7 MSN :xubeisi at hotmail.com Blog :http://xubeisi.blog.edu.cn Chinese only...T_T
2006年01月09日 星期一 12:01
在 06-1-9,Beisi Xu<xubeisi at ustc.edu> 写道: > 大小写问题?Image->image? > 按理说windows不区分大小写啊,怪.你的lib目录也有些怪,一会c:,一会d:的 windows是不分,但python分呀。 BTW:兄弟能不能把没用的东西裁剪一下呀。 -- I like python! My Blog: http://www.donews.net/limodou NewEdit Maillist: http://groups.google.com/group/NewEdit
Zeuux © 2025
京ICP备05028076号