我有一个小的要求,使一个特定的属性作为主键,这样通过使用这个属性我想访问同一行的其他属性。请任何人帮助我。如何使一个特定的属性作为python的主键
说明::我有4个数组,我想检索对应于我选择的行的数组中的数据。简单地说,我使用Python作为数据库并存储检索基于其他元组的值一个特定的列值。
import string
import sys
from Tkinter import *
import win32com.client
win = Tk()
win.title("Sorting the list of employees as of desire")
win.geometry("600x600+200+50")
win.resizable()
class Emp(object):
def __init__(self):
i = 0
def save():
b = self.e.get()
#print "The name of employee is", b
n.append(b)
c = self.a.get()
#print "The age of employee is", c
ge.append(c)
idf = self.i.get()
#print "The Ide of the Employee is ", id
idee.append(idf)
de = self.d.get()
# print "The Designation of the Employee is ", de
desi.append(de)
#print "\n"
def clear():
self.e.delete(0, END)
self.a.delete(0, END)
self.i.delete(0, END)
self.d.delete(0, END)
n = []
Label(text="Employee form ", font="Verdana 18 bold italic").pack()
Name = Label(text="Name ", font="Verdana 10 bold ")
Name.place(relx=0.1, rely=0.5)
Name.pack()
self.e = Entry(text="Enter the name of the employee ")
self.e.place(relx=0.5, rely=0.5, anchor=CENTER)
self.e.insert(0, "Name of Employee")
self.e.pack()
ge = []
age = Label(text="Age ", font="Verdana 10 bold ")
age.place(relx=0.1, rely=0.5)
age.pack()
self.a = Entry(text="Enter the age of the employee ")
self.a.place(relx=0.5, rely=0.5, anchor=CENTER)
self.a.insert(0, "Age of Employee")
self.a.pack()
idee = []
ide = Label(text="ID ", font="Verdana 10 bold ")
ide.place(relx=0.1, rely=0.5)
ide.pack()
self.i = Entry(text="Enter the ID of the employee ")
self.i.place(relx=0.5, rely=0.5, anchor=CENTER)
self.i.insert(0, "IDE of Employee")
self.i.pack()
desi = []
des = Label(text="Designation ", font="Verdana 10 bold ")
des.place(relx=0.1, rely=0.5)
des.pack()
self.d = Entry(text="The Designation of the employee ")
self.d.place(relx=0.5, rely=0.5, anchor=CENTER)
self.d.insert(0, "Designation of Employee")
self.d.pack()
def printf():
global i
xyz = len(n)
for i in range(0, xyz):
print "Details are ::", "Name is :", n[i], "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i]
print "\n"
def sorting():
sor = raw_input("Enter a to sort from A or z to sort in reverse order")
xyz = len(n)
if sor == 'a' or'A' :
n.sort()
for i in range(0, xyz):
print "Details are ::", "Name is :", n[i]#, "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i]
print "\n"
elif sor == 'z' or 'Z':
n.sort()
print "Details are ::", "Name is :", n[i], "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i]
n.reverse()
for i in range(0, xyz):
print "Details are ::", "Name is :", n[i]#, "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i]
print "\n"
btn = Button(text="Save ", font="verdana 12 ", command=save)
btn.pack(fill=X, expand=YES)
btn.place(relx=0.85, rely=0.06, anchor=CENTER)
btnc = Button(text="Next", font="verdana 12 ", command=clear)
btnc.pack(fill=X, expand=YES)
btnc.place(relx=0.85, rely=0.90, anchor=CENTER)
btnp = Button(text="print", font="verdana 12 ", command=printf)
btnp.pack(fill=X, expand=YES)
btnp.place(relx=0.6, rely=0.9, anchor=CENTER)
btns = Button(text="Sort", font="verdana 12 ", command=sorting)
btns.pack(fill=X, expand=YES)
btns.place(relx=0.3, rely=0.9, anchor=CENTER)
abj = Emp()
win.mainloop()
这是我的代码。在所有的值存储在各自的数组后。我想根据名称对它们进行排序,我写的代码我得到的输出是只有名称属性的排序数组,而我希望所有相应的值也被排序。请帮我
你可以发布一些代码来说明你试过了什么,你得到了什么输出以及你想要什么输出? – Makoto 2011-12-26 05:44:44
我已经给出我的代码..请通过它并priovide我ans – 2011-12-26 05:55:18
感谢您提供的代码,但你已经消除了原来的问题,使这个线程中的评论远没有用。您能否重新发布原始问题的内容,并在您的代码下面填写?谢谢。 – 2011-12-26 05:56:39