के साथ पाइथन में Baffling AttributeError मैं एक त्रुटि निष्पादित करने के लिए पाइथन में फ़ंक्शन कॉल करते समय एक त्रुटि से परेशान और निराश हूं। मैंने यह सुनिश्चित करने के लिए जांच की है कि मेरे पास स्पेस इंडेंट्स (अस्पष्ट जांचना) के बजाय टैब नहीं हैं। मैंने यहां इस्तेमाल किए गए सम्मेलन का पालन किया है: http://zetcode.com/db/sqlitepythontutorial/ और यहां: How to check the existence of a row in SQLite with Python?सरल स्क्लाइट क्वेरी
क्या कोई यह देख सकता है कि यह प्रतीत होता है कि यह अच्छा कोड एक त्रुटि क्यों फेंक देगा? मैं अभी कोडब्लिंड हूँ। धन्यवाद!
त्रुटि:
File "paddle-csv-import.py", line 23, in getscore
cur1.execute("SELECT pts FROM matchpoints WHERE s1 =? and s2 = ? and \
AttributeError: 'builtin_function_or_method' object has no attribute 'execute'
प्रासंगिक कोड:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import sqlite3 as lite
import trueskill as ts
import sys
import csv
import datetime
#global declarations
# global variables
season = '1011'
unknum = 0
# global functions
def getscore(sets):
con1 = None
con1 = lite.connect('match_setup.db')
cur1 = con1.cursor
cur1.execute("SELECT pts FROM matchpoints WHERE s1=? and s2=? and s3=?",(sets))
homepoints = cur1.fetchone()
if homepoints is None:
print('There is no component named %s'%sets)
return(homepoints);
यह समारोह एक पाश से कहा जाता है, पर बाद में, और ठीक से पारित कर दिया डेटा की जा रही है। मैंने यह सुनिश्चित करने के लिए फ़ंक्शन में एक प्रिंट लाइन फंस ली है कि डेटा ठीक से पारित किया जा रहा है और यह मिला है, जो सही है।
('3-6', '1-6', '0-0')
मैंने उसी डीबी पर सीधे समान, सटीक क्वेरी को चलाया है और परिणाम अपेक्षित रूप से वापस आते हैं।
'cur1 = con1.cursor()' सूचना समारोह कॉल '()' – RedBaron
RedBaron, आप सही हैं - धन्यवाद! –