Python: python的简单表达式计算器
这是一个简单的表达式计算器, 不太懂用Tkinter写GUI, 参考了别人的代码
from __future__ import division
from Tkinter import Tk, Entry, Button, Label, mainloop
from tkFont import Font
def get_value ():
v = ''
try:
v = eval(text.get()) #use eval to calculate the vlaue of the text
except:
pass
if isinstance(v, (int, float, long)):
pass
else:
v = 'Error...'
label.config(text = v) #use config to change the text
top = Tk()
top.title("calculator")
ft = Font(family = 'Courier New', size = 12)
text = Entry(top, font = ft)
button = Button(top, text = 'Ok', command = get_value)
label = Label(text = '(+ - * / % **)', font = ft)
Enter = lambda x: x.keycode == 13 and get_value()
Key = lambda x: label.config(text = '(+ - * / % **)')
text.bind('<Key>', Enter) #when the key is enter, execute the function Enter
text.focus()
text.bind('<Button-1>', Key) #when click the left-key, execute the function Key
text.pack()
button.pack()
label.pack()
mainloop()
相关文档:
赖勇浩(http://laiyonghao.com)
今天(2009年5月31日) OurPNP.org 搞了个聚会活动,弄了十几二十个人在广州海珠广场的堂会呆了五个小时,创下了我在 K 房呆的最长时间纪录。应他们的邀请,我做了个题为《用 python 快速搭建网游服务器》的小演讲,因为那边的电视竟然不能接电脑,所以讲的时候没有能够参照 PPT 来讲,观 ......
对数据库的操作基本分为三步:
连接数据库
根据需要执行SQL语句,接受返回值
关闭连接
我们正常的数据库应该都离不开这三步,下来说说如何使用python中的MySQLdb模块进行这些操作:
首先,我们需要把MySQLdb引入到程序中
import MySQLdb
然后开始数据库操作
1.数据库连接
conn = MySQLdb. ......
闲来无事, 玩玩python...
是采用有道翻译, 然后抓取网页的.
import re, urllib
url="http://dict.youdao.com/search?le=eng&q="
print ("input q to exit")
while 1:
word = raw_input(">>>")
if word=="q":
exit()
else:
word = word.replace(' ', '+')
url += word
u ......
前一段时间试着用这三种语言简单的写了关于文件拷贝的程序,发现c#和python的api惊人的相似,对于文件的操作这两种语言非常的方便。都没有加异常的处理
C#源代码:
public static void CopyFile(string source, string destination)
& ......
multiprocessing — Process-based “threading” interface
Introduction
multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Glo ......