2014-03-28 132 views
-1

我檢索從MSSQL的最後一個ID,並試圖增加它,並與ID存儲呸名字。但我得到「屬性錯誤:Nonetype對象有沒有屬性‘ID’ 」 ..The代碼和錯誤放在這裏:Nonetype對象有沒有屬性「ID」

import Tkinter,tkFileDialog 
import shutil  
import pyodbc  
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=PAVAN;DATABASE=video;Trusted_Connection=yes;") 
cursor = cnxn.cursor() 
cursor.execute("SELECT TOP 1 id FROM files ORDER BY id DESC ") 

while 1: 
    row = cursor.fetchone() 
    if not row: 
     break 
    print row.id  
cnxn.close()  
middle = Tkinter.Tk() 

def withdraw():  
    dirname = tkFileDialog.askopenfilename(parent=middle,initialdir="H:/",title='Please 
select a file')  
    a="H:python(test)\py_"+row.id+".mp4"  
    b=shutil.copyfile(dirname,a) 

    if b!="":  
     print "Successfully Copied"  
    else:  
     print "Could not be copied" 

B = Tkinter.Button(middle, text ="UPLOAD", command = withdraw)  
middle.geometry("450x300+100+100")  
middle.configure(background="black")  
B.pack() 
middle.mainloop() 

我得到的錯誤是:

Traceback (most recent call last): 
    File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__ 
     return self.func(*args) 
    File "C:\Users\hp\Desktop\upload.py", line 20, in withdraw 
    a="H:python(test)\py_"+row.id+".mp4" 
AttributeError: 'NoneType' object has no attribute 'id' 

回答

0

這當您嘗試從對象,它是獲取ID屬性發生無型, 這裏有一個案例:

>> a = None 
>> a.id 
AttributeError: 'NoneType' object has no attribute 'id' 

因此,它可能是這樣的對象是無類型的,你要打印row.id

您可以使用檢查行的類型:

type(**row**) 

至於 迪帕克

相關問題